<?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>Francois Faubert &#187; PHP</title>
	<atom:link href="http://www.francoisfaubert.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.francoisfaubert.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Sep 2009 19:00:31 +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>Stop reinventing the wheel</title>
		<link>http://www.francoisfaubert.com/2007/11/08/stop-reinventing-the-wheel/</link>
		<comments>http://www.francoisfaubert.com/2007/11/08/stop-reinventing-the-wheel/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 15:20:34 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PDO]]></category>

		<guid isPermaLink="false">http://fake.themusictank.com/2007/11/08/stop-reinventing-the-wheel/</guid>
		<description><![CDATA[For years, I&#8217;ve been using an early version of a PHP database access class written by a friend of mine (hi Max!). I&#8217;ve been tweaking it over and over again, spending way too much time on it considering the end result.
Well I&#8217;m tired of reinventing the wheel. Since it&#8217;s fifth installment, PHP provides an API [...]]]></description>
			<content:encoded><![CDATA[<p>For years, I&#8217;ve been using an early version of a PHP database access class written by a friend of mine (hi Max!). I&#8217;ve been tweaking it over and over again, spending way too much time on it considering the end result.</p>
<p>Well I&#8217;m tired of reinventing the wheel. Since it&#8217;s fifth installment, PHP provides an API easing access to all types of databases called <a href="http://ca.php.net/manual/en/ref.pdo.php">PDO functions</a>. All the features you need are in there, coded in C by NASA engineers and is likely better than anything I could come up with.</p>
<p>You really should read up on the PDO if you currently maintain a custom database access object &#8212; or none at all. Also, as the documentation points out, this is not a full-blown database abstraction layer (to run MySQL, Oracle or others transparently) it&#8217;s a data-access abstraction layer (so make sure your queries are properly formed for the database you want to use).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2007/11/08/stop-reinventing-the-wheel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving PHP Sessions to MySQL</title>
		<link>http://www.francoisfaubert.com/2007/06/16/saving-php-sessions-to-mysql/</link>
		<comments>http://www.francoisfaubert.com/2007/06/16/saving-php-sessions-to-mysql/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 20:23:24 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[The Music Tank]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Sessions]]></category>

		<guid isPermaLink="false">http://fake.themusictank.com/2007/06/16/saving-php-sessions-to-mysql/</guid>
		<description><![CDATA[In most cases, websites don&#8217;t necessarily need to be managed by sessions that end as soon as the users closes their browser. Most websites now offer to keep their session alive for whatever amount of time. This is really less of a hassle for your users and adds to the positive user experience.
Learning what not [...]]]></description>
			<content:encoded><![CDATA[<p>In most cases, websites don&#8217;t necessarily need to be managed by sessions that end as soon as the users closes their browser. Most websites now offer to keep their session alive for whatever amount of time. This is really less of a hassle for your users and adds to the positive user experience.</p>
<p><strong>Learning what not to do </strong></p>
<p>On TMT, I used to handle sessions manually by storing the encrypted value of the user&#8217;s id in a cookie. That&#8217;s is highly unrecommended for security reasons as its fairly easy to hack your way around using an id that isn&#8217;t yours (and which might be the administrator&#8217;s!). </p>
<p>I experimented by storing so-called &#8216;unique&#8217; values I generated and stored in MySQL to have better validation when decrypting the cookie, but since you can spoof most $_SERVER values (which provides the user&#8217;s IP), it really wasn&#8217;t good enough.</p>
<p><strong>Hardcore PHP-ing</strong></p>
<p>You can override the whole session object using PHP&#8217;s <code><a href="http://www.php.net/manual/en/function.session-set-save-handler.php">session_set_save_handler()</a></code> function. Basically, you re-program what the object does when it reads and writes session values or when it destroys itself.</p>
<p>Instead of writing the session values to a file on the server like the default behavior is set to do, you can redirect the data handling to an insert or update query in your favorite database.</p>
<p><strong>Advantages</strong></p>
<p>The most obvious advantage is that you can keep the sessions alive as long as your server is live, more or less. You can also change the condition of how session expiration are done. For instance, through a simple MySQL query, TMT sessions can be kept for one week before being destroyed if no activity is logged.</p>
<p>I&#8217;ve read it&#8217;s safer to store session values that way too, as a possible hacker would need the database&#8217;s password to access it. While I&#8217;m not sure how harder this method actually makes it for hackers in reality, I really feel safer to use PHP&#8217;s native object rather than a shaky class I would have written.</p>
<p>Fully using PHP&#8217;s native session object allows more flexibility as you are very close to Apache. You can therefore validate with confidence (not blind confidence though) that the user is indeed human and not a spam bot, save the user&#8217;s preferred language or do whatever else your website offers as possible features without fear. In my previous horrible system, it wasn&#8217;t even a possibility.</p>
<p><strong>Examples</strong></p>
<p>Apart from <em>stalker at ruun dot de</em>&#8217;s very good comment on PHP.net&#8217;s documentation page, I found <a href="http://www.tonymarston.net/php-mysql/session-handler.html">Tony Marston</a>&#8217;s version of the object. The latter is harder to grasp as he uses his own object-oriented system to get database data &#8212; that&#8217;s good practice, but a bit harder to learn from. You can also see TMT&#8217;s class in our <a href="http://themusictank.svn.sourceforge.net/viewvc/themusictank/trunk/brain/php_Session.php?revision=22&amp;view=markup">SVN repository</a>.</p>
<p>The important thing is just to understand what you&#8217;re trying to do rather than copy pasting each of our codes. TMT&#8217;s only started working once I grasped the concept.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2007/06/16/saving-php-sessions-to-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Page encoding can stop the PHP parser</title>
		<link>http://www.francoisfaubert.com/2006/11/23/page-encoding-can-stop-the-php-parser/</link>
		<comments>http://www.francoisfaubert.com/2006/11/23/page-encoding-can-stop-the-php-parser/#comments</comments>
		<pubDate>Thu, 23 Nov 2006 15:54:23 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[The Music Tank]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Server Error]]></category>
		<category><![CDATA[Time Loss]]></category>

		<guid isPermaLink="false">http://fake.themusictank.com/2006/11/23/page-encoding-can-stop-the-php-parser/</guid>
		<description><![CDATA[The main PHP Class file of The Music Tank stopped loading altogether yesterday. After scanning lines after lines of code trying to guess what what generating an error I still hadn&#8217;t found the problem until late last night. 
What made it nebulous was that instead of having a message from PHP describing a known error [...]]]></description>
			<content:encoded><![CDATA[<p>The main PHP Class file of The Music Tank stopped loading altogether yesterday. After scanning lines after lines of code trying to guess what what generating an error I still hadn&#8217;t found the problem until late last night. </p>
<p>What made it nebulous was that instead of having a message from PHP describing a known error like &#8221; &#8216;)&#8217; expected on line 64 &#8220;, I was triggering an Internal Server Error on Apache when loading the website and the parser was outputting unicode garbage when I tried to load the class directly from the browser (instead of nothing at all because I don&#8217;t print data right from the class).</p>
<p>I have to admit I could have been a bit keener on the issue just by looking a the garbage the file was making. It turns out that my code editor, TextWrangler, had changed the encoding type of the file from UTF-8 to the Macintosh charset when I inserted the © character straight in the document without using it&#8217;s HTML counterpart <code>&amp;copy</code>.</p>
<p>The change of charset and/or the use of special characters in the source code stopped the PHP parser. I can&#8217;t explain why as I don&#8217;t have much access to the configuration files to my server&#8217;s PHP version nor do I know how PHP reads the .php files, but I think it was due to the use of multiple charsets in the same rendering call. For instance the main class was using the Mac charset while the subclasses it was importing used UTF-8 encoding.</p>
<p>The frustrating part is really how this whole deal was created out of laziness. Apple offers a wide selection of special characters by doing a [alt + most keys] combination. I thought I&#8217;d save some time by using their copyright sign instead of sticking with &amp;copy.</p>
<p>At least, this episode forced me into cleaning the quote quite a lot by splitting my pages into modules which reflect the content&#8217;s architecture. The Tank should show a light performance boost now. Very light though, hehehe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2006/11/23/page-encoding-can-stop-the-php-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
