<?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>andre bluehs &#187; security</title>
	<atom:link href="http://andrebluehs.net/blog/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrebluehs.net/blog</link>
	<description>nerdy, webby, smelly?</description>
	<lastBuildDate>Wed, 25 May 2011 23:35:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP and Security</title>
		<link>http://andrebluehs.net/blog/2009/04/php-and-security/</link>
		<comments>http://andrebluehs.net/blog/2009/04/php-and-security/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 20:56:53 +0000</pubDate>
		<dc:creator>Andre</dc:creator>
				<category><![CDATA[Securiy]]></category>
		<category><![CDATA[Webby]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://andrebluehs.net/blog/?p=49</guid>
		<description><![CDATA[Recently, I have been doing some work with php and having users log in. One of the projects I&#8217;m working on is something where we&#8217;re pretty much rolling our own mini-CMS. We have users log in, manage sessions, check timeouts, etc. In php, security is pretty easy to do well (for my example&#8230; i&#8217;m being [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I have been doing some work with php and having users log in. One of the projects I&#8217;m working on is something where we&#8217;re pretty much rolling our own mini-CMS. We have users log in, manage sessions, check timeouts, etc. In php, security is pretty easy to do well (for my example&#8230; i&#8217;m being very general here). The rest of this post will skip over explaining how redirections and sessions work in php.<br clear="none"/><br />
This is the easiest way to prevent someone who is not logged in from viewing the current page:<br clear="none"/><br />
<code>if (!isset($_SESSION['user_id'])) header("Location: login.php");</code><br clear="none"/><br />
What executes is if the user is not logged in (or has timed out and <code>$_SESSION['user_id']</code> has been <code>unset()</code>). Then the user is redirected to login.php or any appropriate page.<br clear="none"/><br />
However, what happens when you run into something like an indexing or archiving bot that ignores headers? You run into <a href="http://thedailywtf.com/Articles/WellIntentioned-Destruction.aspx">this tdwtf problem</a>. That article also tackles deletion-by-href instead of deletion-by-form. That&#8217;s a whole different beast. What can you do about this problem? Is there a more secure alternative to using headers?<br clear="none"/><br />
<strong>Headers are just dandy</strong><br clear="none"/><br />
What most people (including me up until recently) assume is that after sending the header, all things stop. For a bot, this is not the case, it goes on it&#8217;s merry way executing the rest of the code. In the case of the above article, with dire consequences. But fret not! There is a simple solution. <br clear="none"/><br />
<code>exit();</code><br clear="none"/><br />
By putting <code>exit();</code> at the end of that line of code, the script stops executing, and while the bot may not be redirected, disaster is averted. So, your code will now look like:<br clear="none"/><br />
<code>if (!isset($_SESSION['user_id'])){<br />
    header("Location: login.php");<br />
    exit();<br />
}</code><br clear="none"/><br />
Hope this helps stave off any disaster.</p>
 <img src="http://andrebluehs.net/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=49" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://andrebluehs.net/blog/2009/04/php-and-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

