<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeRemix</title>
	<atom:link href="http://coderemix.com/feed" rel="self" type="application/rss+xml" />
	<link>http://coderemix.com</link>
	<description>Web Development Articles and Book Reviews</description>
	<lastBuildDate>Tue, 02 Feb 2010 15:11:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Voice Gadget not displaying on iGoogle</title>
		<link>http://coderemix.com/troubleshooting/google-voice-gadget-not-displaying-on-igoogle</link>
		<comments>http://coderemix.com/troubleshooting/google-voice-gadget-not-displaying-on-igoogle#comments</comments>
		<pubDate>Tue, 02 Feb 2010 15:03:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=163</guid>
		<description><![CDATA[Google Voice is one of the most practical Web apps I have ever found, it&#8217;s just amazing. A few days ago, I decided to add the Google Voice Gadget on my iGoogle page and I encountered a problem with it. I would just get a blank white box. The box was empty, there was no [...]]]></description>
			<content:encoded><![CDATA[<p>Google Voice is one of the most practical Web apps I have ever found, it&#8217;s just amazing. A few days ago, I decided to add the Google Voice Gadget on my iGoogle page and I encountered a problem with it. I would just get a blank white box. The box was empty, there was no data. I&#8217;m using Safari 4.0.3 on a Mac OS X, but I have seen people reporting this problem on the Chrome browser too.<br />
<div id="attachment_164" class="wp-caption aligncenter" style="width: 590px"><img src="http://coderemix.com/wp-content/uploads/2010/02/empty-google-voice-gadget.jpg" alt="Blank Google Voice  Gadget" title="Blank Google Voice Gadget" width="580" height="358" class="size-full wp-image-164" /><p class="wp-caption-text">Blank Google Voice  Gadget</p></div></p>
<p>To make it work (at least for now), just add an &#8220;<em>s</em>&#8221; to &#8220;<em>http://www.google.com/ig</em>&#8221; on the Address Bar of your browser, like this: &#8220;<em>http<strong>s</strong>://www.google.com/ig</em>&#8221;<br />
<div id="attachment_165" class="wp-caption aligncenter" style="width: 590px"><img src="http://coderemix.com/wp-content/uploads/2010/02/google-voice-gadget.jpg" alt="Google Voice Gadget" title="Google Voice Gadget" width="580" height="358" class="size-full wp-image-165" /><p class="wp-caption-text">Google Voice Gadget</p></div> </p>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/troubleshooting/google-voice-gadget-not-displaying-on-igoogle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep your Search Engine Ranking with 301 Redirects</title>
		<link>http://coderemix.com/apache/keep-your-search-engine-ranking-with-301-redirects</link>
		<comments>http://coderemix.com/apache/keep-your-search-engine-ranking-with-301-redirects#comments</comments>
		<pubDate>Fri, 15 Jan 2010 22:39:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Search Engine Optimization]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=158</guid>
		<description><![CDATA[If there ever comes the time when you redesign your Website completely, unfortunately search engines will not be very sympathetic about that. Suppose you move a page from http://mysite.com/news/iphone to http://mynewdomain.com/tech-news/iphone. If the search engines already indexed your original Website hyperlinks and your Website&#8217;s fans bookmarked some of your Webpages, you will want to redirect [...]]]></description>
			<content:encoded><![CDATA[<p>If there ever comes the time when you redesign your Website completely, unfortunately search engines will not be very sympathetic about that. Suppose you move a page from http://mysite.com/news/iphone to http://mynewdomain.com/tech-news/iphone. If the search engines already indexed your original Website hyperlinks and your Website&#8217;s fans bookmarked some of your Webpages, you will want to redirect them to the new URL. </p>
<p>One of the best ways to redirect search engines and Website visitors to a new Webpage location is by using <strong>301 redirects</strong>. You can configure Apache with the Redirect directive to redirect traffic from an old url to a new one. The Redirect directive takes several arguments</p>
<ul>
<li>redirect code</li>
<li>original URL location</li>
<li>destination URL</li>
</ul>
<p>You can set the status as a numeric HTTP code. <strong>HTTP code 301 represents a permanent change</strong>.</p>
<p>By using 301 Redirects you will let the search engines know that this is a new, permanent location and you might keep your search engine ranking. Keep in mind that any changes to your Website navigation structure can negatively influence your search engine rankings.</p>
<p>Create a new .htaccess or in your current .htaccess file.</p>
<p>To redirect a specific URL to a new URL</p>
<blockquote><p>Redirect 301 /news/iphone http://mynewdomain.com/tech-news/iphone</p></blockquote>
<p>To redirect everything from your original domain name to a new domain name.</p>
<blockquote><p>Redirect 301 / http://mynewdomain.com</p></blockquote>
<p>Upload the .htaccess file to your server. Make sure do include the dot on the filename &#8220;.htaccess&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/apache/keep-your-search-engine-ranking-with-301-redirects/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysqldump Access is denied error on Vista</title>
		<link>http://coderemix.com/troubleshooting/mysqldump-access-is-denied-vista</link>
		<comments>http://coderemix.com/troubleshooting/mysqldump-access-is-denied-vista#comments</comments>
		<pubDate>Fri, 15 Jan 2010 19:24:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=141</guid>
		<description><![CDATA[Today, I was trying to make a copy a MySQL database that resides in my laptop with Windows Vista. I ran the mysql dump command but I got an error: &#8220;Access is denied&#8221;.
The mysqldump command is simple. I never forgot it&#8217;s basic syntax.
mysqldump -u username -p dbname > dbbackup.sql
The reason why I never did is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://coderemix.com/wp-content/uploads/2010/01/20.png" alt="Windows Vista MySQL Access Denied" title="Windows Vista MySQL Access Denied" width="200" height="150" class="alignleft size-full wp-image-140" />Today, I was trying to make a copy a MySQL database that resides in my laptop with Windows Vista. I ran the mysql dump command but I got an error: &#8220;Access is denied&#8221;.</p>
<p>The mysqldump command is simple. I never forgot it&#8217;s basic syntax.</p>
<blockquote><p>mysqldump -u username -p dbname > dbbackup.sql</p></blockquote>
<p>The reason why I never did is because the first time I tried it on a Windows XP machine, I logged in to MySQL prompt and tried to run the mysqldump command. It took me a couple hours to find out that I didn&#8217;t need to login to MySQL before running the command. I was just supposed to go to the MySQL bin directory and run the executable command. </p>
<p>Anyways, I suppose you are not making the same mistake because you are already getting the frustrating &#8220;Access is denied&#8221; error. Why?</p>
<p>Well, one of the differences between XP and Windows Vista you may have noticed first is that Vista keeps on asking for your permission when you try to do certain tasks. &#8220;Windows needs your permission to continue&#8221;.</p>
<p>Seems that Vista doesn&#8217;t let you create new files using the Command Prompt. So it&#8217;s a Windows error rather than a MySQL error.</p>
<p><img src="http://coderemix.com/wp-content/uploads/2010/01/20-1.png" alt="Windows Vista Run as administrator Command Prompt" title="Windows Vista Run as administrator Command Prompt" width="371" height="118" class="alignleft size-full wp-image-139" /></p>
<p>So here is what you do: specify you are an Administrator for Vista by right-clicking the Command Prompt icon and select &#8220;Run as administrator&#8221; from the menu. That&#8217;s it. Navigate to the MySQL bin directory, run the mysqldump command and it should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/troubleshooting/mysqldump-access-is-denied-vista/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Cookies-enabled check in 3 effortless steps</title>
		<link>http://coderemix.com/php/php-cookies-enabled-check</link>
		<comments>http://coderemix.com/php/php-cookies-enabled-check#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:59:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=135</guid>
		<description><![CDATA[Months ago, I coded my first simple CMS. I went into my client&#8217;s office to proudly show him how my new CMS worked. I sat down on his chair to show him using his own computer how it worked. After the user logs in, the system was supposed to take you to a control panel. [...]]]></description>
			<content:encoded><![CDATA[<p>Months ago, I coded my first simple CMS. I went into my client&#8217;s office to proudly show him how my new CMS worked. I sat down on his chair to show him using his own computer how it worked. After the user logs in, the system was supposed to take you to a control panel. So I tried to login once and it sent me back to the login page&#8230; uhmmm&#8230; weird. I tried to login a second time and it redirects me again to the login page. Third time: nothing! I blushed from embarrassment. As I later discovered, my client had disabled cookies on his browser and that was the reason why my login script didn&#8217;t work. My PHP login system used sessions to keep the user logged-in, and since cookies were disabled on his browser sessions nor cookies would work. Now, every time I code a Website that uses cookies or sessions, I include a cookies-enabled check script and you should too.</p>
<p>Click the following link to see a live example of a PHP cookies-enabled check.</p>
<p>We will check if cookies are enabled by following these steps:</p>
<ul>
<li>Define a cookie</li>
<li>Reload the page</li>
<li>Check if the cookie we just defined is still there</li>
</ul>
<p>Sounds plain and simple, right? It is! So, how do we express these 3 steps in code?</p>
<h2>Steps 1 and 2: Define a cookie and reload the page</h2>
<p>I&#8217;m going to explain steps 1 and 2 together so you understand how we use the $_GET['redirected'] variable included in the script.</p>
<pre name="code" class="php">
if(!isset($_GET['redirected'])) {
    setcookie ('mycookie', 'test', time() + 60);
    header('location:'.$_SERVER['PHP_SELF'].'?redirected=1');
}</pre>
<p>First, confirm that the page hasn&#8217;t been redirected already by checking if the $_GET['redirected'] variable is set. If the $_GET['redirected'] variable hasn&#8217;t been set, then the page will reload and set the $_GET['redirected'] variable on the query string. Just be careful not to create an endless loop of page redirection.</p>
<p>Before you output anything from your script, you should define the cookie. setcookie() defines a cookie named &#8220;mycookie&#8221; with value of &#8220;test&#8221; and the cookie is set to expire in sixty seconds or one minute. We set the cookie to expire in one minute because after we check if cookies are enabled or not we won&#8217;t longer need the cookie.</p>
<h2>Step 3: Check if the cookie we just defined is still there</h2>
<pre name="code" class="php">
$cookie_message = '';
if(isset($_GET['redirected']) and $_GET['redirected']==1) {
    if(!isset($_COOKIE['mycookie'])) {
        $cookie_message = '
<p style="background-color:#FFCCFF; padding:10px;">Cookies are NOT enabled on your browser. In order for us to process your request, we require cookies to be enabled. Please configure your browser to allow cookies.

';
    }
    else {
        $cookie_message = '
<p style="background-color:#99CCFF; padding:10px;">Cookies are enabled on your browser.

';
    }
}</pre>
<p>Initialize the $cookie_message variable, which will be echoed later to let the user know if his/her browser accepts cookies. </p>
<p>Then, an if statement tests the $_GET['redirected'] variable to verify if the page has been reloaded. If the page has been reloaded, the next if/else statement checks if the $_COOKIE['mycookie'] variable exists and assigns a value to $cookie_message accordingly to be echoed later in the script.</p>
<p>This tutorial should help you get an overall idea of how to check if cookies are enabled. Customize the code to meet your needs. Don&#8217;t forget to include a cookies test script in all Web applications that handle cookies or sessions in some way.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/php/php-cookies-enabled-check/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sams Teach Yourself Apache 2 in 24 Hours</title>
		<link>http://coderemix.com/book-reviews/sams-teach-yourself-apache-2-in-24-hours</link>
		<comments>http://coderemix.com/book-reviews/sams-teach-yourself-apache-2-in-24-hours#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:56:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Book Reviews]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=133</guid>
		<description><![CDATA[Author(s): Daniel López Ridruejo
Publisher: Sams Publishing
Sams Teach Yourself Apache 2 in 24 Hours convers a wide range of topics about Apache but, in my opinion, half of the book would be hard for begginers to understand. 
PROS
Hour 1, Apache and the Web, introduces the reader to basic concepts such as DNS, SSL, URL, HTTP status [...]]]></description>
			<content:encoded><![CDATA[<p>Author(s): Daniel López Ridruejo<br />
Publisher: Sams Publishing</p>
<p><img src="http://coderemix.com/wp-content/uploads/2010/01/6-1.jpg" alt="Sams Teach Yourself Apache 2 in 24 Hours" title="Sams Teach Yourself Apache 2 in 24 Hours" width="250" height="250" class="alignleft size-full wp-image-74" />Sams Teach Yourself Apache 2 in 24 Hours convers a wide range of topics about Apache but, in my opinion, half of the book would be hard for begginers to understand. </p>
<h2>PROS</h2>
<p>Hour 1, Apache and the Web, introduces the reader to basic concepts such as DNS, SSL, URL, HTTP status codes and more.</p>
<p>Hour 5, Using Apache to Server Static Content, contains information and easy configuration tasks for URL Redirection, MIME types, Icons for Bookmarks and others.</p>
<h2>CONS</h2>
<p>In some sections, it tries to cover a lot of information in a few pages and lacks easy-to-follow, practical examples. For a Sams Teach Yourself book, it needs more step-by-step instructions on how to accomplish certain tasks.</p>
<p>For example, I found some concepts in Hour 7, Restricting Access, hard to grasp such as File-Based Authentication, Database File-Based Access Control and Digest-Based Authentication.</p>
<p>Also, Hour 22, Dynamic URI Resolution with mod_rewrite, would be difficult for a begginner to comprehend and customize the examples to his/her own server.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/book-reviews/sams-teach-yourself-apache-2-in-24-hours/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check your magic quotes configuration</title>
		<link>http://coderemix.com/php/how-to-check-your-magic-quotes-configuration</link>
		<comments>http://coderemix.com/php/how-to-check-your-magic-quotes-configuration#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:53:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=129</guid>
		<description><![CDATA[If you want to check your magic quotes setting, you can use the PHP function get_magic_quotes_gpc. This function gets the current configuration setting of magic quotes gpc and returns 0 if magic quotes are off, 1 otherwise.
To find out your current magic quotes configuration simply create a PHP file with the following code:
if(get_magic_quotes_gpc()) {
  [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to check your magic quotes setting, you can use the PHP function <a href="http://us.php.net/manual/en/function.get-magic-quotes-gpc.php" target="_blank">get_magic_quotes_gpc</a>. This function gets the current configuration setting of magic quotes gpc and returns 0 if magic quotes are off, 1 otherwise.</p>
<p>To find out your current magic quotes configuration simply create a PHP file with the following code:</p>
<pre name="code" class="php">if(get_magic_quotes_gpc()) {
    echo 'Magic Quotes is On';
}
else {
    echo 'Magic Quotes if Off';
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/php/how-to-check-your-magic-quotes-configuration/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to disable magic quotes using an .htaccess file</title>
		<link>http://coderemix.com/php/disable-magic-quotes-htaccess</link>
		<comments>http://coderemix.com/php/disable-magic-quotes-htaccess#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:51:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=126</guid>
		<description><![CDATA[I recommend you turn off magic quotes and escape characters using mysql_real_escape_string instead. If you server configuration allows it, you can disable magic quotes using an Apache .htaccess file.
Magic quotes is a feature intended to help prevent security breaches in scripts written by PHP beginners. Read the article Protect your script from hackers: Protect your [...]]]></description>
			<content:encoded><![CDATA[<p>I recommend you turn off magic quotes and escape characters using mysql_real_escape_string instead. If you server configuration allows it, you can disable magic quotes using an Apache .htaccess file.</p>
<p>Magic quotes is a feature intended to <a href="http://us.php.net/manual/en/security.magicquotes.why.php" target="_blank">help prevent security breaches in scripts written by PHP beginners</a>. Read the article Protect your script from hackers: <a href="/mysql/sql-injection-attack-prevention" target="_blank">Protect your script from hackers: SQL injection attack prevention</a> to find out why you should turn magic quotes off. </p>
<p>If you don&#8217;t have access to the PHP configuration file, you can also disable magic quotes using an .htaccess file. You just have to add the following line:</p>
<blockquote><p>php_flag magic_quotes_gpc Off</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/php/disable-magic-quotes-htaccess/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to disable magic quotes using php.ini</title>
		<link>http://coderemix.com/php/disable-magic-quotes-php-ini</link>
		<comments>http://coderemix.com/php/disable-magic-quotes-php-ini#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:48:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=124</guid>
		<description><![CDATA[I recommend you turn off magic quotes and escape characters using mysql_real_escape_string instead.
Magic quotes is a feature intended to help code written by beginners from being dangerous. Read the article Protect your script from hackers: SQL injection attack prevention to find out why you should turn magic quotes off. 
Open your PHP configuration file (php.ini) [...]]]></description>
			<content:encoded><![CDATA[<p>I recommend you turn off magic quotes and escape characters using mysql_real_escape_string instead.</p>
<p>Magic quotes is a feature intended to <a href="http://us.php.net/manual/en/security.magicquotes.why.php" target="_blank">help code written by beginners from being dangerous</a>. Read the article <a href="/mysql/sql-injection-attack-prevention" target="_blank">Protect your script from hackers: SQL injection attack prevention</a> to find out why you should turn magic quotes off. </p>
<p>Open your PHP configuration file (php.ini) and look for the magic_quotes_gpc line. If the setting is equal to On just change it to Off.</p>
<blockquote><p>magic_quotes_gpc = Off</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/php/disable-magic-quotes-php-ini/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build Your Own Database Driven Website Using PHP &amp; MySQL</title>
		<link>http://coderemix.com/book-reviews/build-your-own-database-driven-website-using-php-mysql</link>
		<comments>http://coderemix.com/book-reviews/build-your-own-database-driven-website-using-php-mysql#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:45:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Book Reviews]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=122</guid>
		<description><![CDATA[Author(s): Kevin Yank
Publisher: SitePoint Pty. Ltd.
Excellent book for people with absolutely no knowledge of PHP and MySQL. 
I&#8217;m a self-taught programmer. After learning HTML, CSS and some Javascript, I found out I also had to learn a server-side programming language. Build Your Own Database Driven Website Using PHP &#038; MySQL was the first PHP/MySQL book [...]]]></description>
			<content:encoded><![CDATA[<p>Author(s): Kevin Yank<br />
Publisher: SitePoint Pty. Ltd.</p>
<p>Excellent book for people with absolutely no knowledge of PHP and MySQL. </p>
<p>I&#8217;m a self-taught programmer. After learning HTML, CSS and some Javascript, I found out I also had to learn a server-side programming language. Build Your Own Database Driven Website Using PHP &#038; MySQL was the first PHP/MySQL book I grabbed and it really got me started into the subject.</p>
<h2>PROS</h2>
<p>This book uses a hands-on approach. The code and examples it contains are well-explained. </p>
<p>It guides you throught the PHP and MySQL installation in Windows, Linux and Mac. I followed the instructions and installed PHP and MySQL in Windows and Linux, but I haven&#8217;t tried Mac.</p>
<p>It does a very good job at teaching you the MySQL basics in chapter 2, teaching you the PHP basics in chapter 3 and then working with both PHP and MySQL in chapter 4. Learning how to integrate PHP and MySQL together feels effortless.</p>
<p>This book also walks you through programming a content management system that administers jokes, categories and authors. </p>
<p>Chapter 5, Relational Database Design, discusses a subject which is difficult to grasp for some beginners, but it&#8217;s very well explained in this book.</p>
<p>Chapter 7, Content Formatting and Submission, briefly explains Regular Expressions and illustrates it by examples.</p>
<p>The last chapters cover more advanced topics such as granting database priviledges, locking tables, grouping select results, file uploads and cookies.</p>
<h2>CONS</h2>
<p>Any PHP/MySQL beginner should learn how to prevent MySQL injection attacks as soon as possible and this book doesn&#8217;t cover the subject.</p>
<p>There is almost no form submission validation in the PHP code examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/book-reviews/build-your-own-database-driven-website-using-php-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protect your script from hackers: by validating HTTP GET variable names</title>
		<link>http://coderemix.com/php/protect-your-script-from-hackers-by-validating-http-get-variable-names</link>
		<comments>http://coderemix.com/php/protect-your-script-from-hackers-by-validating-http-get-variable-names#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:41:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://coderemix.com/?p=118</guid>
		<description><![CDATA[$_GET data is usually passed to the browser to indicate what page or article to load from a Website and may be used to make a query to your MySQL database. You probably already have protected your MySQL database from SQL injection attacks. Let&#8217;s take an extra step to protect the valuable data your MySQL [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://coderemix.com/wp-content/uploads/2010/01/15-2.png" alt="hacker" title="hacker" width="150" height="150" class="alignleft size-full wp-image-119" />$_GET data is usually passed to the browser to indicate what page or article to load from a Website and may be used to make a query to your MySQL database. You probably already have <a href="/mysql/sql-injection-attack-prevention">protected your MySQL database from SQL injection attacks</a>. Let&#8217;s take an extra step to protect the valuable data your MySQL tables hold. You can prevent users from messing with <a href="/php/url-query-string">URL Query Strings</a> by validating validating $_GET data before you execute anything with it.</p>
<p>As defined at php.net,<a href="http://us.php.net/manual/en/reserved.variables.get.php" target="_blank"> $_GET</a> is &#8220;an associative array of variables passed to the current script via the HTTP GET method.&#8221;</p>
<p>To grasp an idea of what we are trying to do, let&#8217;s create a PHP file named querystrings.php. We can examine the contents of the $_GET array by using the <a href="http://us3.php.net/manual/en/function.print-r.php" target="_blank">print_r function</a>. Type the following code in our querystrings.php file</p>
<pre name="code" class="php">
print_r($_GET);
</pre>
<p>Enter the following on your browser:</p>
<blockquote><p>http://myhost/path/querystrings.php?name=Leo&#038;location=Texas</p></blockquote>
<p>Of course, replace &#8220;myhost/path&#8221; according to your server&#8217;s settings.</p>
<p>Your browser should display something like this:</p>
<blockquote><p>Array ( [username] => Leo [location] => Texas )</p></blockquote>
<p>There is two $_GET variables: $_GET['username'] and $_GET['location']. You could easily echo the data inside each variable. But how about allowing only certain $_GET variable names?</p>
<h2>Compile a list of the $_GET variable names you use and make sure only those are processed</h2>
<p>Let&#8217;s say you only use 3 different $_GET variables names throughtout your whole Website. The variables names are pageid, sectionid and articleid. You use those variables to display the pages&#8217; content. You don&#8217;t want any user messing with the URL. So let&#8217;s restrict what they can input on as the URL.</p>
<p>You could throw the following code at an include file and include it at the top of every page on your Website. Since $_GET is an array, we use a foreach loop to find out the array keys being passed and confirm they are one of the three accepted array keys. If they are not, the user will be redirected to an error page.</p>
<pre name="code" class="php">
foreach($_GET as $key => $value) {
    if($key != 'pageid' and $key != 'sectionid' and $key! = 'articleid') {
        header('location:errorpage.php');
        exit();
    }
}
</pre>
<p>What if you have developed a Website or Web application that uses dozens of $_GET variables names? You could create an array or even a MySQL table with the allowed $_GET variable names and use it to validate them.</p>
<pre name="code" class="php">
$allow = array('pageid', 'sectionid', 'articleid');

foreach($_GET as $key => $value) {
    $valid = false;
    foreach($allow as $key_allow => $value_allow) {
        if($key==$value_allow) {
            $valid = true;
        }
    }

    if($valid==false) {
        header('location:errorpage.php');
        exit();
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://coderemix.com/php/protect-your-script-from-hackers-by-validating-http-get-variable-names/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
