<?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>phoenixheart - portfolio &#38; more &#187; php</title>
	<atom:link href="http://www.phoenixheart.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phoenixheart.net</link>
	<description>phoenixheart - portfolio &#38; more</description>
	<lastBuildDate>Wed, 23 Mar 2011 09:47:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<script type="text/javascript">
if (typeof Meebo == "undefined") {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){

	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'phoenixheartnet_bo16we'});	}</script>	<item>
		<title>php.js &#8211; Javascript equivalents for PHP functions</title>
		<link>http://www.phoenixheart.net/2009/02/phpjs-javascripts-equivalent-for-php-functions/</link>
		<comments>http://www.phoenixheart.net/2009/02/phpjs-javascripts-equivalent-for-php-functions/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 15:59:58 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Client stuffs]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=227</guid>
		<description><![CDATA[Being a PHP developer, there must be certain times when you have to deal with Javascript. And if you&#8217;re rather confident with PHP when in the meantime suck at JS just like me, you must have more than once googled for the JS equivalent of that very useful/powerful base64_encode, or htmlentities, or array_merge, or strpos, [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">B</span>eing a PHP developer, there must be certain times when you have to deal with Javascript. And if you&#8217;re rather confident with PHP when in the meantime suck at JS just like me, you must have more than once googled for the JS equivalent of that very useful/powerful <a href="http://www.php.net/base64_encode">base64_encode</a>, or <a href="http://www.php.net/htmlentities">htmlentities</a>, or <a href="http://www.php.net/array_merge">array_merge</a>, or <a href="http://www.php.net/strpost">strpos</a>, you_name_it.</p>
<p>Well, I&#8217;m not any exception, until I got acknowledged of a JS project called <a href="http://phpjs.org/">php.js</a> originally started by <a href="http://kevin.vanzonneveld.net/techblog/article/phpjs_licensing/">Kevin van Zonneveld</a>. I have used this in more than one of my projects and it just works perfect for me without any hassles, so maybe I should feature it in return. <span id="more-227"></span></p>
<p>You can tell, the project is all about porting PHP functions into Javascript. Yes, many of those are there, but under a different name or one step away &#8211; like PHP&#8217;s <a href="http://www.php.net/sin">sin</a> and JS&#8217; <a href="http://www.w3schools.com/jsref/jsref_sin.asp">Math.sin</a>. Some others however, are not that easy to obtain in Javascript &#8211; I&#8217;m talking about md5, date, serialize etc. and those array stuffs. It even deals with file system, with the support of the <a href="http://www.w3.org/TR/XMLHttpRequest/">XMLHttpRequest object</a> (therefore these functions may fail if the browser doesn&#8217;t support it). </p>
<p>The project is active and it seems Kevin, with the great help from other contributors, is constantly expanding it. A list of available (successfully ported) methods can be found <a href="http://phpjs.org/functions/index">here</a> &#8211; nearly 300 (!) each with detailed code and examples. You can just copy the function code and embed it into your script to start using right away, or download the full packages for everything. </p>
<p>I, for myself, can&#8217;t understand how there are such good people in this world: put huge effort into something just to give away, expecting nothing in return. </p>
<p>Are you using of this wonderful project in your own? If so how about featuring it?</p>
<img style='display:none' id="post-227-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/02/phpjs-javascripts-equivalent-for-php-functions/',title:'php.js &#8211; Javascript equivalents for PHP functions',tweet:'Being a PHP developer, there must be certain times when you have to deal with Javascript. And if you',description:'Being a PHP developer, there must be certain times when you have to deal with Javascript. And if you'})"><script type='text/javascript'>document.getElementById("post-227-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/02/phpjs-javascripts-equivalent-for-php-functions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Kohana PHP framework</title>
		<link>http://www.phoenixheart.net/2009/01/kohana-php-framework/</link>
		<comments>http://www.phoenixheart.net/2009/01/kohana-php-framework/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 04:24:06 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=210</guid>
		<description><![CDATA[You know, I&#8217;m a die-hard fan of CodeIgniter. Among a lot of PHP frameworks out there, I prefer CI over Zend, Cake, Symfony etc. because of its speed, efficiency, and most importantly, simplicity. Just download it, unzip into a folder, and call it done. To me, a framework that costs me more than 10 minutes [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">Y</span>ou know, I&#8217;m a die-hard fan of <a href="http://www.codeigniter.com">CodeIgniter</a>. Among a lot of PHP frameworks out there, I prefer CI over Zend, Cake, Symfony etc. because of its speed, efficiency, and most importantly, simplicity. Just download it, unzip into a folder, and call it done. To me, a framework that costs me more than 10 minutes to install is considered failure &#8211; Symfony is one.</p>
<p>With simplicity and efficiency being the priority in mind, several days ago, I discovered <a href="http://www.kohanaphp.com">Kohana</a> and was impressed. As clearly specified on its homepage, Kohana was originally based on CodeIgniter, so CI users should find no difficulties migrating. Then, along its (community-driven) development way, Kohana has grown quite a bit, and now looks like a very promising PHP framework. Among its features:</p>
<ul>
<li>Highly secure</li>
<li>Extremely lightweight</li>
<li>Short learning curve</li>
<li>Uses the MVC pattern</li>
<li>100% UTF-8 compatible</li>
<li>Loosely coupled architecture</li>
<li>Extremely easy to extend</li>
</ul>
<p><span id="more-210"></span><br />
And the things make it stand out from the crowd:</p>
<ol>
<li>Community, not company, driven. Kohana development is driven by a team of dedicated people that need a framework for fast, powerful solutions.</li>
<li>Strict PHP 5 OOP. Offers many benefits: visibility protection, automatic class loading, overloading, interfaces, abstracts, and singletons.</li>
<li>Extremely lightweight. Kohana has no dependencies on PECL extensions or PEAR libraries. Large, monolithic libraries are avoided in favor of optimized solutions.</li>
<li>GET, POST, COOKIE, and SESSION arrays all work as expected. Kohana does not limit your access to global data, but offers filtering and XSS protection.</li>
<li>True auto-loading of classes. True on-demand loading of classes, as they are requested in your application.</li>
<li>No namespace conflicts. All classes are suffixed to allow similar names between components, for a more coherent API.</li>
<li>Cascading resources offer unparalleled extensibility. Almost every part of Kohana can be overloaded or extended without editing core system files. Modules allow multi-file plugins to be added to your application, transparently.</li>
<li>Library drivers and API consistency. Libraries can use different &#8220;drivers&#8221; to handle different external APIs transparently. For example, multiple session storage options are available (database, cookie, and native), but the same interface is used for all of them. This allows new drivers to be developed for existing libraries, which keeps the API consistent and transparent.</li>
<li>Powerful event handler. Observer-style event handlers allow for extreme levels of customization potential.</li>
<li>Rapid development cycle. Rapid development results in faster response to user bugs and requests.</li>
</ol>
<p>You can tell that, originally a fork from CodeIgniter, Kohana should inherit the best from CI when having many improvements. Yes, it&#8217;s true. First, it&#8217;s PHP 5, so you can take full advantages of the new features available in this version. Second, it doesn&#8217;t limit your data in POST and SESSION as CI does (by default, CI disables GET, and it was a nightmare for me trying to integrate Google Custom Search into my CI-based website). Third, it has cool libraries, with the most powerful being <abbr title="Object Relational Mapping">ORM</abbr>, which is a must-have for serious enterprise application.</p>
<p>With this being said, I&#8217;ll not dust away CodeIgniter anytime soon. Nevertheless, CI is already mature, with a good userbase, when Kohana is still in its beginning phase and thus has true support limitations. Both have their own pros and cons, so while sticking with CI, I will start playing around with Kohana.</p>
<p>To my readers: please spread the words! Kohana is definitely a very promising PHP framework. By featuring it on your own blog, you&#8217;re helping an free, useful, open-source, community-driven application grow. That also is contribution <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img style='display:none' id="post-210-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/01/kohana-php-framework/',title:'Kohana PHP framework',tweet:'You know, I&#8217;m a die-hard fan of CodeIgniter. Among a lot of PHP frameworks out there, I prefer',description:'You know, I&#8217;m a die-hard fan of CodeIgniter. Among a lot of PHP frameworks out there, I prefer'})"><script type='text/javascript'>document.getElementById("post-210-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/01/kohana-php-framework/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>IP address to geographic details</title>
		<link>http://www.phoenixheart.net/2009/01/ip-address-to-geographic-details/</link>
		<comments>http://www.phoenixheart.net/2009/01/ip-address-to-geographic-details/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 08:33:08 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[geo]]></category>
		<category><![CDATA[geographic]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=204</guid>
		<description><![CDATA[Today I received a small project to detect the country of web visitors. I&#8217;ve never done something like that before, so as always, I started googling around. And it turned out that it&#8217;s not that complex &#8211; there is a company called MaxMind that offers APIs to look up geographic details from an IP address. The [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">T</span>oday I received a small project to detect the country of web visitors. I&#8217;ve never done something like that before, so as always, I started googling around. And it turned out that it&#8217;s not that complex &#8211; there is a company called <a href="http://www.maxmind.com">MaxMind</a> that offers <a href="http://www.maxmind.com/app/api">APIs</a> to look up geographic details from an IP address. The APIs are written in a variety of languages like C, Perl, Java, Python, Ruby, C#, VB.NET, Pascal, Javascript, and of course, PHP. </p>
<p>For this project, I decided to go with PHP version which has a <a href="http://pear.php.net/package/Net_GeoIP/">NET_GeoIP PEAR package</a>. Just download it, along with the free data files (they have paid ones also) &#8211; <a href="http://www.maxmind.com/app/geolitecountry">Geo Lite Country</a> if you want the country details only, or <a href="http://www.maxmind.com/app/geolitecity">Geo Lite City</a> if you want extra stuffs like city, region, latitude and longtitude etc. In this post, I&#8217;ll go with City version.<span id="more-204"></span></p>
<p>Now, with everything downloaded and extracted into a folder, start with an empty index.php file and fill it with some code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;path/to/file/GeoIP.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// define a new instance of Net_GeoIP class</span>
<span style="color: #000088;">$geoip</span> <span style="color: #339933;">=</span> Net_GeoIP<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path/to/file/GeoLiteCity.dat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
try <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$geoip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lookupLocation</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Handle exception</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The function lookupLocation() from class NET_GeoIP accepts a string parameter in IP format &#8211; something like &#8220;210.245.17.13&#8243; and returns a Location object which contains several useful geographic information. If you run this script on your localhost however, nothing will be printed. That is because in such a case, $_SERVER['REMOTE_ADDR'] is a local IP &#8211; most often 127.0.0.1 &#8211; which cannot tell us anything. Have you heard this quote &#8220;There is nothing like 127.0.0.1&#8243;?</p>
<p>So for testing purpose, let&#8217;s modify the above code a bit, so that it can accept an optional query parameter as an IP.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;path/to/file/GeoIP.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// define a new instance of Net_GeoIP class</span>
<span style="color: #000088;">$geoip</span> <span style="color: #339933;">=</span> Net_GeoIP<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path/to/file/GeoLiteCity.dat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test_ip'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test_ip'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
try <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$geoip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lookupLocation</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Handle exception</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now if you&#8217;ve set it everything correctly in place, browse to index.php?test_ip=210.124.12.3 will show something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">object<span style="color: #009900;">&#40;</span>Net_GeoIP_Location<span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">#2 (10) {
</span>  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;countryCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;KR&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;countryName&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;Korea, Republic of&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;region&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;11&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;city&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;Seoul&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;postalCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  <span style="color: #009900; font-weight: bold;">NULL</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;latitude&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  float<span style="color: #009900;">&#40;</span><span style="color:#800080;">37.5664</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;longitude&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  float<span style="color: #009900;">&#40;</span><span style="color:#800080;">126.9997</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;areaCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  <span style="color: #009900; font-weight: bold;">NULL</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;dmaCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  <span style="color: #009900; font-weight: bold;">NULL</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;countryCode3&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;KOR&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Similarly, index.php?test_ip=128.54.13.8 shows</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">object<span style="color: #009900;">&#40;</span>Net_GeoIP_Location<span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">#2 (10) {
</span>  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;countryCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;US&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;countryName&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;United States&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;region&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;CA&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;city&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;La Jolla&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;postalCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;92093&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;latitude&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  float<span style="color: #009900;">&#40;</span><span style="color:#800080;">32.8807</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;longitude&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  float<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color:#800080;">117.2359</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;areaCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">858</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;dmaCode&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  float<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">825</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;countryCode3&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;USA&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Extremely useful, isn&#8217;t it? With these information on hand, there&#8217;s no limit of what we can do to improve user interaction and much more.</p>
<p>A simple demo of this can be found <a href="http://www.phoenixheart.net/projects/countrydetector">here</a>.</p>
<img style='display:none' id="post-204-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/01/ip-address-to-geographic-details/',title:'IP address to geographic details',tweet:'Today I received a small project to detect the country of web visitors. I&#8217;ve never done somet',description:'Today I received a small project to detect the country of web visitors. I&#8217;ve never done somet'})"><script type='text/javascript'>document.getElementById("post-204-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/01/ip-address-to-geographic-details/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>AJAX Random Posts &#8211; a new WP plugin (of mine)</title>
		<link>http://www.phoenixheart.net/2008/12/ajax-random-posts/</link>
		<comments>http://www.phoenixheart.net/2008/12/ajax-random-posts/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 09:46:10 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=164</guid>
		<description><![CDATA[Firstly, I&#8217;d like to show off a bit: hey I&#8217;ve caught up with the crowd, now both of my sites (this one and Thica.net) are upgraded to WordPress 2.7 &#8211; well, let&#8217;s hope that it is not prone to new vulnerabilities. The most significant change is the admin section &#8211; for the first time in [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">F</span>irstly, I&#8217;d like to show off a bit: hey I&#8217;ve caught up with the crowd, now both of my sites (this one and <a href="http://www.thica.net">Thica.net</a>) are upgraded to WordPress 2.7 &#8211; well, let&#8217;s hope that it is not prone to new vulnerabilities. The most significant change is the admin section &#8211; for the first time in my life I have to admit that it looks even better than the front-end. Is it good, or is it bad (my baby), I don&#8217;t know, but if you are using my plugin(s) and are worried about the compatibility, rest assured: they all work in this new versions. That is, of course, unless you tell me that they&#8217;re not.</p>
<p>But hey, this post is not about WordPress 2.7! There are hundreds of blogs out there babbling about it already! If you&#8217;re a careful reader (definition: a careful reader is someone who reads something from the title on), you probably know it, I&#8217;ve managed to used some free time to write another WP plugin called <a href="http://wordpress.org/extend/plugins/ajax-random-posts/">AJAX Random Posts</a>, and this post is more or less its homepage.</p>
<p>As its name is saying, AJAX Random Posts (AjaxRP) display a list of randomly chosen posts from your WordPress-powered blog. Yeah, it&#8217;s nothing new, such a concept is very popular and has been greatly done by several plugins before. The limitation of those plugins however, is the lack of cache plugins compatibility. For example, you install a random post plugin. Then a visitor comes to post A, and under a post he&#8217;s served with 5 other random ones, let&#8217;s say C, Y, M, K, and J. If you have WP-Super Cache enabled on your blog, the post A is cached for, like, one hour. During that one hour, <em>any</em> visitor that reads post A will be served with its <em>cached</em> version, with C, Y, M, K, and J following. You must agree with me, it&#8217;s not so random anymore <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p>So, the only difference my AjaxRP is making is its &#8220;AJAX&#8221; part. With AjaxRP, the random list is NOT generated along with post A. Instead, it makes an AJAX call to the server after the page is loaded (more precisely, after the DOM is ready) and retrieves a list of random posts. This way, it works regardless of whether or not you have a cache plugin installed. That means, each page refresh shows a new random list. And I guess that is what should be called &#8220;random&#8221;.<span id="more-164"></span></p>
<h3>FAQ</h3>
<p>Q: Do you provide a template tag/ post tag?<br />
A: Absolutely. If you don&#8217;t want the random posts to be display after every post, just set &#8220;Automatically display the random posts in a single post page?&#8221; to &#8220;No&#8221; in the Settings page, and</p>
<ul>
<li>Manually put <strong>&lt;!&#8211;ajaxrp&#8211;&gt;</strong> at the end of your post, or</li>
<li>Place this php code: <strong>&lt;?php if (function_exists(&#8216;ajaxrp&#8217;)) ajaxrp(); ?&gt;</strong><br />
at a proper place in your template&#8217;s <strong>single.php</strong> page</li>
</ul>
<p>Q: Where can I find a demo?<br />
A: Right here! Take a look at the end of this post.</p>
<p>Q: How do I support this plugin?<br />
A: Please link back to this post or blog about it. Also I would appreciate a lot if you can rate this plugin 5 stars in the WordPress repository.</p>
<h3>History</h3>
<p>Full history can be found <a href="http://wordpress.org/extend/plugins/ajax-random-posts/other_notes/">here</a>.</p>
<h3>Download</h3>
<p>Head <a href="http://wordpress.org/extend/plugins/ajax-random-posts/">here</a>.</p>
<img style='display:none' id="post-164-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2008/12/ajax-random-posts/',title:'AJAX Random Posts &#8211; a new WP plugin (of mine)',tweet:'Firstly, I&#8217;d like to show off a bit: hey I&#8217;ve caught up with the crowd, now both of my s',description:'Firstly, I&#8217;d like to show off a bit: hey I&#8217;ve caught up with the crowd, now both of my s'})"><script type='text/javascript'>document.getElementById("post-164-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2008/12/ajax-random-posts/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>Convert a database from latin1 to utf8 charset (aka. Thica.net redesigned)</title>
		<link>http://www.phoenixheart.net/2008/11/convert-a-database-from-latin1-to-utf8-charset-aka-thicanet-redesigned/</link>
		<comments>http://www.phoenixheart.net/2008/11/convert-a-database-from-latin1-to-utf8-charset-aka-thicanet-redesigned/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 07:22:39 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=153</guid>
		<description><![CDATA[If it&#8217;s been a while since my last update on this blog, then I&#8217;d say sorry, I was working on a re-design of my favorite thica.net site. Ok, I&#8217;ll be honest here: I didn&#8217;t invent anything, instead I only took a copy of the great Notepad Chaos theme from Smashing Magazine and spent some time [...]]]></description>
			<content:encoded><![CDATA[<p>If it&#8217;s been a while since my last update on this blog, then I&#8217;d say sorry, I was working on a re-design of my favorite <a href="http://www.thica.net">thica.net</a> site. Ok, I&#8217;ll be honest here: I didn&#8217;t invent anything, instead I only took a copy of the great <a href="http://www.smashingmagazine.com/2008/08/20/notepad-chaos-a-free-wordpress-theme/">Notepad Chaos theme</a> from Smashing Magazine and spent some time tweak it to my needs. Well, it may sound simple, but it was NOT at all&#8230;</p>
<p>Especially when I came into this serious problem: MySQL data charset converting.</p>
<p>Let me say more clearly. I&#8217;m a Vietnamese, and I like Vietnamese poems (at least good ones), so Thica.net (which means Poetry.net in English) is naturally written in Vietnamese, and is nothing more than a normal WordPress installation. The thing is, when first installed Thica.net, the charset of the database (and everything inside it) was set to &#8220;latin1&#8243; by default. When not being a big problem with English speaker, for multilingual sites it&#8217;s prone to big troubles, like:</p>
<ul>
<li>Incorrect search results</li>
<li>Wrong order of sorting: in Vietnamese alphabet table, letter &#8220;Đ&#8221; comes right after &#8220;D&#8221;, but in my site it came not sooner than &#8220;Y&#8221;, when &#8220;Ý&#8221; was placed just before &#8220;A&#8221; &#8211; whoops.</li>
</ul>
<p>So along with the redesign, I decided that Thica.net&#8217;s database needed to be revamped. Easy spoken, indeed. But not that easy to do.<span id="more-153"></span></p>
<p>First, MySQL internally supports conversion between charsets. Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`table_name`</span> CONVERT <span style="color: #993333; font-weight: bold;">TO</span> CHARACTER <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #ff0000;">'utf8'</span>;</pre></div></div>

<p>You may have guessed it, this query doesn&#8217;t help much. While the table&#8217;s charset has been indeed converted into utf8, the data remains the same, means a bunch of meaningless characters like &#8220;Tráº§n Dáº§n&#8221;, &#8220;Pháº¡m Tiáº¿n Duáº­t&#8221;, &#8220;Nguyá»…n Má»¹&#8221; and so on.</p>
<p>Then, I read somewhere that you can dump the entire database into a text file, and use Notepad++ to convert the encoding into UTF-8, then restore the dump back. Or, you can use iconv library. Or, the multibyte functions in PHP. None worked for me.</p>
<p>After some researching in vain, I came to this question: why does querying the latin1 database and display the retrieved data on a page (in utf-8) always works correctly? It turned out that, like an ox, MySQL somehow decided to take the hard and heavy part, like this:</p>
<ol>
<li>First, client machine requests data using a query</li>
<li>Server quietly converts the (latin1) data into UTF-8 and returns it</li>
<li>Client machine displays the properly formatted data on browser</li>
</ol>
<p>So it flashed through my mind: I&#8217;d take part in in the final step. Instead of displaying the good data however, I will save it somewhere, like in a dump, to be accessible later. And like a real dump, there should be queries to drop and create tables also. Here is the code I wrote:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># if your database is big, do some preparations
</span><span style="color: #666666; font-style: italic;"># ini_set('memory_limit', '256M');
</span><span style="color: #666666; font-style: italic;"># ini_set('max_execution_time', 120);
</span>
<span style="color: #666666; font-style: italic;"># some config data
</span><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PASS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FILE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf8data-dump.sql'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>HOST<span style="color: #339933;">,</span> USER<span style="color: #339933;">,</span> PASS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span>DB<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># retrieves a list of table names from the database
</span><span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SHOW TABLES FROM '</span> <span style="color: #339933;">.</span> DB<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># for each table, get its structure
</span>	<span style="color: #000088;">$table_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>-- TABLE STRUCTURE OF <span style="color: #006699; font-weight: bold;">$table_name</span>--<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$table_struct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW CREATE TABLE &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$table_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$table_struct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_struct</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># add a DROP IF EXISTS query
</span>	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DROP TABLE IF EXISTS <span style="color: #006699; font-weight: bold;">$table_name</span>; <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># add a CREATE TABLE query
</span>	<span style="color: #666666; font-style: italic;"># remember, we must replace latin1 charset with utf8
</span>	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latin1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_struct</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;; <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># now, the data
</span>	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>-- DATA OF <span style="color: #006699; font-weight: bold;">$table_name</span>--<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$table_data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM <span style="color: #006699; font-weight: bold;">$table_name</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># if the table is empty, hell with it
</span>	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_data</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$table_name</span> VALUES &quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># populate the data
</span>	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data_row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'('</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data_row</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'<span style="color: #009933; font-weight: bold;">%s</span>',&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rtrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'),'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rtrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$str</span>; <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># write the (formatted) data into the dump file.
</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">FILE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wb'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This script worked for me (this post will make no sense otherwise). After running this it in my browser, I got a dump that can be use to restore a perfect utf8 database (well, not really perfect, as I&#8217;ll tell below, but acceptable). </p>
<p>The limitation of this script is, it doesn&#8217;t support the collates. A table created with utf8 charset will have a default collate being utf8_general_ci, which isn&#8217;t preferred over utf8_unicode_ci (like in these charts <a href="http://www.collation-charts.org/mysql60/mysql604.utf8_general_ci.european.html">here</a> and <a href="http://www.collation-charts.org/mysql60/mysql604.utf8_unicode_ci.european.html">here</a>. At least, my categories are not correctly sorted until I manually set the column `wp_terms`.`name` to utf8_unicode_ci. </p>
<p>The final line: Have you known yet? <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  My new Thica.net is <a href="http://www.thica.net">here</a>.</p>
<img style='display:none' id="post-153-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2008/11/convert-a-database-from-latin1-to-utf8-charset-aka-thicanet-redesigned/',title:'Convert a database from latin1 to utf8 charset (aka. Thica.net redesigned)',tweet:'If it&#8217;s been a while since my last update on this blog, then I&#8217;d say sorry, I was workin',description:'If it&#8217;s been a while since my last update on this blog, then I&#8217;d say sorry, I was workin'})"><script type='text/javascript'>document.getElementById("post-153-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2008/11/convert-a-database-from-latin1-to-utf8-charset-aka-thicanet-redesigned/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 1.7.0 released!</title>
		<link>http://www.phoenixheart.net/2008/10/codeigniter-170-released/</link>
		<comments>http://www.phoenixheart.net/2008/10/codeigniter-170-released/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 10:23:19 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Blahblahblah]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=118</guid>
		<description><![CDATA[Yes, it&#8217;s been a while, and finally my favorite PHP framework has released its latest version 1.7.0 (Actually it was some 7 days ago but I missed it, what a shame). When the previous version (1.6.3) was just more or less about maintenance and bug fixes, 1.7.0 makes a step further to add many new [...]]]></description>
			<content:encoded><![CDATA[<p>Yes, it&#8217;s been a while, and finally <a href="http://codeigniter.com/">my favorite PHP framework</a> has released its latest version 1.7.0 (Actually it was some 7 days ago but I missed it, what a shame).</p>
<p>When the previous version (1.6.3) was just more or less about maintenance and bug fixes, 1.7.0 makes a step further to add many new and enhanced features. To name a few (from the <a href="http://codeigniter.com/user_guide/changelog.html">Change Log</a>):</p>
<ul>
<li>Added a new <a href="http://codeigniter.com/user_guide/libraries/form_validation.html">Form Validation Class</a>. It simplifies setting rules and field names, supports arrays as field names, allows groups of validation rules to be saved in a config file, and adds some helper functions for use in view files[...] <em>(Me: Perfect. The old validation class was really a failure of CI, as it was ugly and prone to misunderstanding)</em></li>
<li>Updated the <a href="http://codeigniter.com/user_guide/libraries/sessions.html">Sessions class</a> so that any custom data being saved gets stored to a database rather than the session cookie (assuming you are using a database to store session data), permitting much more data to be saved. <em>(Me: I don&#8217;t save session data into database, so this doesn&#8217;t sound like a big change to me)</em></li>
<li>Added the ability to store libraries in subdirectories within either the main &#8220;libraries&#8221; or the local application &#8220;libraries&#8221; folder[...] <em>(Me: Finally. It has always pissed me up for not being able to organize my libraries)</em></li>
<li>Added the ability to assign library objects to your own variable names when you use <kbd>$this-&gt;load-&gt;library()</kbd> [...] <em>(Me: Yes, I&#8217;ve been wondering why this was not available in previous versions, when it DID with controllers and models)</em></li>
<li>Added controller class/method info to <a href="http://codeigniter.com/user_guide/general/profiling.html">Profiler class</a> and support for multiple database connections.</li>
<li>Improved the &#8220;auto typography&#8221; feature and moved it out of the helper into its own <a href="http://codeigniter.com/user_guide/libraries/typography.html">Typography Class</a>. <em>(Me: I didn&#8217;t pay notice to this feature. Looks like a VERY useful class now. Must make use of it)</em></li>
<li>Improved performance and accuracy of <kbd>xss_clean()</kbd>, including reduction of false positives on image/file tests</li>
<li>[...]</li>
<li>Added support for mb_strlen in the <a href="http://codeigniter.com/user_guide/libraries/form_validation.html">Form Validation</a> class so that multi-byte languages will calculate string lengths properly. <em>(Me: So it didn&#8217;t make use of mb_strlen() in the past? OMG!)</em></li>
</ul>
<p>With many other new features and bug fixes, this is definitely worth an upgrade. Way to go, CodeIgniter!</p>
<p>Update: Sorry, forgot this. You can download the latest version <a href="http://codeigniter.com/download.php">here</a>.</p>
<img style='display:none' id="post-118-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2008/10/codeigniter-170-released/',title:'CodeIgniter 1.7.0 released!',tweet:'Yes, it&#8217;s been a while, and finally my favorite PHP framework has released its latest version ',description:'Yes, it&#8217;s been a while, and finally my favorite PHP framework has released its latest version '})"><script type='text/javascript'>document.getElementById("post-118-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2008/10/codeigniter-170-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Six common mistakes in PHP</title>
		<link>http://www.phoenixheart.net/2008/10/six-common-mistakes-in-php/</link>
		<comments>http://www.phoenixheart.net/2008/10/six-common-mistakes-in-php/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 05:36:43 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[mistakes]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=41</guid>
		<description><![CDATA[Okay, so PHP is cool, PHP rocks, PHP is easy to learn… However, just because it’s cool and easy doesn’t mean that you know everything about it. There are gurus (YES!!! LOTS OF THEM!!!) and then there are newbies (WHOHOO!!! Why am I so exciting?). As a guru, you know do-and-don’ts. But what if you’re [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">O</span>kay, so PHP is cool, PHP rocks, PHP is easy to learn… However, just because it’s cool and easy doesn’t mean that you know everything about it. There are gurus (YES!!! LOTS OF THEM!!!) and then there are newbies (WHOHOO!!! Why am I so exciting?). As a guru, you know do-and-don’ts. But what if you’re new to PHP? Don’t panic. Here is a list of top six mistakes in PHP (when I say “top” I mean the “most common” things) that I’ve set out based on my own blood-(not-really)-and-sweat experience.</p>
<h3>1. No or little understanding about HTTP methods</h3>
<p><strong>What’s the point here?</strong></p>
<p>Everybody uses form, but not everybody knows what “GET” and “POST” really do. As a result, many PHP developers tend to get user’s input data from $_REQUEST, thinking “oh, whatever you send, I’ll catch ‘em all”. That’s not so good, really. Think about $_REQUEST as a merge between $_GET and $_POST, now instead of posting through a form, a user can just attach his (malicious) data via the query string, press Enter, and you’re doomed.</p>
<p><strong>How to fix?</strong></p>
<p>You should spent some extra time to learn what GET and POST are, and what they’re doing with the web (well then, after some careful studying you may find that it’s not really secure using POST, since a medium user can easily fake POST data too, but it’s a different story).</p>
<p>Also note that sometimes PHP’s $_GET and $_POST don’t contain any of the input data. This likely happens in a server-to-server data transfer, and now you must parse the raw data yourself, instead of relying on PHP parser. Something like $data = file_get_contents(’php://input’); if you’re ready with that.<br />
<span id="more-41"></span></p>
<h3>2. Little understanding on PHP types</h3>
<p><strong>Yes, what’s so bad?</strong></p>
<p>As a newbie, especially if you’re coming from another strong-typed language like C#, you may find it confused with types in PHP. Then, you don’t know how to do a good comparison operator, neither can you be sure if that 500-line-of-code function returns the correct data type you need. The result? Your PHP code is messy, with unnecessary lines and comments (yeah, comments are good, but only if you don’t overuse them).</p>
<p><strong>How to fix?</strong></p>
<p>Actually it’s not about fixing. Read more, practise more, until you (and your boss) consider yourself OK. If you want to make sure it’s a string, an array etc., make use of PHP’s built-in range of “is_” functions, like is_array, is_string, is_null… If you want an exact comparison, keep in mind that weird “===” operator. Remember that empty($var) returns boolean TRUE with a null, 0 (number), ‘0′ (the string 0), ” (an empty string), an array with no elements, a non-asigned variable, and the FALSE itself. Play around, it’s the key.</p>
<h3>3. Misunderstanding about (external) file including</h3>
<p><strong>Huh?</strong></p>
<p>Like, you create two common files call “header.inc.php” and “footer.inc.php”. Also you put a “functions.inc.php” and “database.class.php” into play. Now with each page, you include() the four php files. Isn’t it fast? convenience? easy to maintain?</p>
<p>YES!!! You rock!!! That’s the way it should be!!!</p>
<p>But wait. Do you know that everything has its own risks? No? Go ask <a href="http://www.google.com/">here</a>.</p>
<p>Just kidding. The thing is, PHP offers many methods to including another file into your current script. And you should take all of them into account, or open your doors saying “Hi, Mister Exploit, my pleasure to meet you!”.</p>
<p><strong>How?</strong></p>
<p>Not that complex. In PHP to include a file, we have at least four ways, include(), include_once(), require(), and require_once(), all accept a string as the file path/name to include and evaluate it. However, they’re different. Little, but can kill.</p>
<p>If you’re trying to include() a missing file, a Warning will be produced, and your script continues. This is sometimes what we want, sometimes not. On the opposite, we have require() which terminates the whole script if there’s any problem with the to-be-included file. Again, sometimes we like it NOT, sometimes we do.</p>
<p>An include_once is equivalent to include(), except that if the file has been included, it won’t be included (and executed) again. The same goes with require_once and require(). This is extremely important, as re-declaring a function in PHP (for now) simply generates a Fatal error. Not what you want, yes?</p>
<p>So isn’t it safer to use include_once() or require_once() all the time? The answer is No. Everything has a price, and in PHP it’s the performance. You must trade your speed for this convenience, so think twice.</p>
<p>Also some tend to use this portion of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
    goToIndexPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">else</span> 
<span style="color: #009900;">&#123;</span> 
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>What does this code do? It acts as a simple front controller, which accepts a “page” parameter via GET. So if the user goes to <em>yoursite.com/?page=news</em>, you’ll serve him your news.php file. Very handy, indeed.</p>
<p>But wait, what if a user by any “accident” wants to go to <em>yoursite.com/?page=../../etc/password</em>? Do you want to serve that guy your password file? I doubt that.</p>
<p>And if allow_url_fopen is turned on in your php.ini, he may wants to visit <em>yoursite.com/?page=http://hissite.com/devil.php</em>… Kaboom! Think about it.</p>
<h3>4. Not using any encryption</h3>
<p><strong>The problem</strong></p>
<p>Once in a while I work as a freelancer, and my jobs are very often done on an existing site &#8211; you know, improving, enhancing, fix bugs, whatever it’s called. And it beats me to see that 50% of the cases, the passwords and other sensitive information are saved nakedly in the database, for any naked eyes to see. Not only it’s a serious security problem, it also hurts policy. You can be sued! Be very afraid!</p>
<p><strong>The fix</strong></p>
<p>Encryption (here I use the term in a common way, ignoring that encrypting and hashing are different) methods are dead simple in PHP. What does it take to encrypt a string in PHP using <a href="http://en.wikipedia.org/wiki/Md5">md5</a>? One line of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$my_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'I am a very sensitive info. Encrypt me please!'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// You can md5 the string normally. This is that one line </span>
<span style="color: #000088;">$encrypted</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// or use a simple yet very efficient technology call &quot;salting&quot; </span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MD5_SALT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'A string No one can GuEss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$encrypted</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_string</span> <span style="color: #339933;">.</span> MD5_SALT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>There! You now have a nearly-impossible-to-decrypt string contained in $encrypted variable. That’s called md5 hashing. How complicated is that? Now save the passwords in encrypted form into database, and sleep well at night. Without a mighty server AND some thousand years, no one can discover your secret behind those 32 characters. Later, if you want to authorize a user for example, hash the typed in password with the same salt and compare the result with the value stored.</p>
<p>There is however one catch with this method: password retrieving feature. No, you simply can’t decrypt the hashed string to give back the password to that absent-minded Bob. As an alternative method, you will have to create another random password for him. This is what I’m doing now:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// generate a random string based on the microtime value </span>
<span style="color: #000088;">$random_string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// now as the string is 32 charaters in length, chop it a bit </span>
<span style="color: #666666; font-style: italic;">// let's say 6 first characters </span>
<span style="color: #000088;">$new_password</span> <span style="color: #339933;">=</span> substring<span style="color: #009900;">&#40;</span><span style="color: #000088;">$random_string</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// save the new password into database. Remember to encrypt it!!! </span>
saveToDatabase<span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// mail Bob</span></pre></td></tr></table></div>

<p>If you prefer returning the old password to our Bob, considering two-way encrypting libraries like <a href="http://www.php.net/mcrypt">mcrypt</a>.</p>
<h3>5. Little care about optimization</h3>
<p><strong>The situation</strong></p>
<p>You’re developing a good site. It’s <a href="http://www.cuil.com/">cuil</a> &#8211; you know what I mean. People know it. Many guys start contributing by writing you good articles. You receive 372 comments with each post. You begin to place ads and earn some money. Wind blows, water flows, men go, dogs bo-wo (that’s how dogs are barking in my country), till one morning you wake up and recognize that it takes five minutes for your website to generate and display a news about Steve Jobs’ heartache. What happened? You can swear that it USED to be lightning fast just ONE MONTH ago! What the hell happened?</p>
<p><strong>The (possibly) cause</strong></p>
<p>Everybody can write code, but not all can/take time to optimize it. <a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%29">According to Wikipedia</a>, optimization is “the process of modifying a system to make some aspect of it work more efficiently or use fewer resources”. The fewer the resources are, the faster your site is. Take a look at this code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$my_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;I will blah 100 times: &quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$my_string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_string</span><span style="color: #339933;">;</span> 
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>When it doesn’t look so bad, there are at least 3 problems within those only 7 lines of code above:</p>
<ol>
<li>Improper use of double quotes (2 times). As PHP will try to parse variables in a double quoted string, it will certainly take extra time to assign “This string” compared to ‘This string’ into a variable.</li>
<li>Not making use of the built-in function str_repeat(). Built-in functions are ALWAYS faster.</li>
<li> The 2 final lines can be combined into one.</li>
</ol>
<p>Now take a look at this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$my_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'I will blah 100 times: '</span><span style="color: #339933;">;</span> 
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_string</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blah'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>How does that look like? Not only it’s shorter, it’s also way cleaner and well optimized. The difference may not be significant in a small idle site, but in a big enterprise application, every bit is gold. So take out the unnecessary code, try to find an equivalent built-in function for that 100 lines of code, try combining your statements, and so on &#8211; <a href="http://reinholdweber.com/?p=3">here</a> is a very good tutorial on this topic. Once you think that your code is perfect, it’s time to considering database optimization, but I’ll talk about it in another post, not here, not now.</p>
<h3>6. Little care about the successors</h3>
<p><strong>Successors? Who are they?</strong></p>
<p>They are the next guys to work with your PHP code (maybe your son, your senior, yourself, or even me).</p>
<p>I’ve seen quite a few of developers who write code like tomorrow’s the end of the world. To name a few:</p>
<ul>
<li>No comments or comments are written in <a href="http://en.wikipedia.org/wiki/Sanskrit">Sanskrit</a>. No, I don’t know Sanskrit, neither my dad, neither my Indian buddy Yousuf. I can’t even read French. I’m dead. Help!!!</li>
<li> Using short tags (&lt;? ?&gt; instead of &lt;?php ?&gt;). What if one day your site moves to another host where short tag was disabled? What if PHP (very likely) decides to remove short tag support from the next version?</li>
<li> Not using a framework. Agreed, there are sites and pages that are too simple, when a framework just means “bloated”. But in other cases, a good framework can only help. It standardizes the way you code, it has security measures, and it’s fast to develop. Learning to use a framework is definitely not a pain in the ass, and there are plenty out there: <a href="http://framework.zend.com/">Zend</a>, <a href="http://cakephp.org/">Cake</a>, <a href="http://codeigniter.com/">CodeIgniter</a>, <a href="http://seagullproject.org/">Seagull</a> etc.</li>
<li> Encrypt your code. Unless you are going to sell your code and giving out a demo, you don’t need such security. It’s gonna be hell when you lose the encryption key. Worst.hell.ever.</li>
</ul>
<p><a href="http://en.wikipedia.org/wiki/Earth#Future">Science has it</a> that our beautiful earth will only vanish after at least 500 million more years. It’s not very near a future, so when you write your code, think about the guys who will be in charge of it tomorrow, and they will thank you.</p>
<img style='display:none' id="post-41-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2008/10/six-common-mistakes-in-php/',title:'Six common mistakes in PHP',tweet:'Okay, so PHP is cool, PHP rocks, PHP is easy to learn… However, just because it’s cool and easy ',description:'Okay, so PHP is cool, PHP rocks, PHP is easy to learn… However, just because it’s cool and easy '})"><script type='text/javascript'>document.getElementById("post-41-blankimage").onload();</script>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2008/10/six-common-mistakes-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 2/36 queries in 0.298 seconds using disk
Object Caching 604/669 objects using disk

Served from: www.phoenixheart.net @ 2012-02-04 02:24:01 -->
