<?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>Skullsauce &#187; php</title>
	<atom:link href="http://www.skullsauce.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skullsauce.com</link>
	<description>It&#039;s kind of like liquid brain waves!</description>
	<lastBuildDate>Mon, 01 Mar 2010 16:40:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Redirecting a URL With PHP Arguments</title>
		<link>http://www.skullsauce.com/redirecting-url-with-php-arguments/</link>
		<comments>http://www.skullsauce.com/redirecting-url-with-php-arguments/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 05:36:30 +0000</pubDate>
		<dc:creator>jendead</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.skullsauce.com/?p=20</guid>
		<description><![CDATA[I gave up on .htaccess for this one!]]></description>
			<content:encoded><![CDATA[<p>Today I spent hours trying to figure out something that I thought was going to be very straightforward and simple. Wrong! Part of the problem is I don&#8217;t work with regular expressions often so the idea of writing .htaccess files is sometimes mystifying to me.</p>
<p>All I really wanted to do seemed easy enough:<br />
Redirect <code>example.com/blog/?p=$variable</code> to <code>example.com/?p=$variable</code>. </p>
<p>I just couldn&#8217;t figure out how to do it with .htaccess, and trial-and-error wasn&#8217;t a good idea since screwing up would throw the dreaded 500 Internal Server Error. I didn&#8217;t have much time so I finally threw in the .htaccess towel and decided to go with what I know &#8211; PHP.</p>
<p>Using <code>$_GET</code> can be dangerous if you don&#8217;t sanitize input, so <code>strip_tags()</code> helps ensure that the user wasn&#8217;t inputting malicious data. Your mileage may vary, and you may need more elaborate validation&#8230; have fun figuring that out. <img src='http://www.skullsauce.com/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Anyway, this code is ugly and really should be cleaned up, but it isn&#8217;t a bad place to start! My example only has one argument, but there&#8217;s no reason you couldn&#8217;t do this with more.</p>
<pre class="brush: php;">
$postid = $_GET['p'];

$postid = strip_tags($postid);

header('Location: http://example.com/?p='.$postid);
</pre>
<p>If anybody knows what the &#8220;proper&#8221; way to do this via .htaccess is, please let me know!</p>



Share this:


	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.skullsauce.com%2Fredirecting-url-with-php-arguments%2F&amp;title=Redirecting%20a%20URL%20With%20PHP%20Arguments&amp;notes=I%20gave%20up%20on%20.htaccess%20for%20this%20one%21" title="del.icio.us"><img src="http://www.skullsauce.com/wp/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.skullsauce.com%2Fredirecting-url-with-php-arguments%2F&amp;title=Redirecting%20a%20URL%20With%20PHP%20Arguments&amp;bodytext=I%20gave%20up%20on%20.htaccess%20for%20this%20one%21" title="Digg"><img src="http://www.skullsauce.com/wp/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.skullsauce.com%2Fredirecting-url-with-php-arguments%2F&amp;t=Redirecting%20a%20URL%20With%20PHP%20Arguments" title="Facebook"><img src="http://www.skullsauce.com/wp/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.skullsauce.com%2Fredirecting-url-with-php-arguments%2F&amp;title=Redirecting%20a%20URL%20With%20PHP%20Arguments" title="StumbleUpon"><img src="http://www.skullsauce.com/wp/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fwww.skullsauce.com%2Fredirecting-url-with-php-arguments%2F" title="Technorati"><img src="http://www.skullsauce.com/wp/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Redirecting%20a%20URL%20With%20PHP%20Arguments%20-%20http%3A%2F%2Fwww.skullsauce.com%2Fredirecting-url-with-php-arguments%2F" title="Twitter"><img src="http://www.skullsauce.com/wp/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.skullsauce.com/redirecting-url-with-php-arguments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/


Served from: reseller14.hrwebservices.net @ 2010-09-08 11:14:22 -->