<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3772193622268326056</id><updated>2012-01-08T23:22:02.486Z</updated><category term='images'/><category term='hijacker'/><category term='Directory'/><category term='replacement'/><category term='domain name'/><category term='hash'/><category term='projects'/><category term='functions'/><category term='GD'/><category term='upgrade'/><category term='include'/><category term='query'/><category term='localhost'/><category term='cookie'/><category term='iteration'/><category term='library'/><category term='array'/><category term='pop3'/><category term='end'/><category term='test'/><category term='Code'/><category term='xampp'/><category term='applications'/><category term='css'/><category term='tips'/><category term='function'/><category term='redirect'/><category term='protection'/><category term='notes'/><category term='asp'/><category term='while'/><category term='facebook'/><category term='xml'/><category term='iis'/><category term='MySQL'/><category term='foreach'/><category term='security'/><category term='commit'/><category term='example'/><category term='php2bin'/><category term='trim'/><category term='memory'/><category term='hacker'/><category term='Bits'/><category term='rollback'/><category term='output'/><category term='Color'/><category term='echo'/><category term='integration'/><category term='monkey'/><category term='html'/><category term='session'/><category term='deny'/><category term='methods'/><category term='framework'/><category term='error'/><category term='request'/><category term='json'/><category term='php2exe'/><category term='Calculations'/><category term='filename'/><category term='mail'/><category term='condition'/><category term='smtp'/><category term='loop'/><category term='dll'/><category term='introduction'/><category term='javascript'/><category term='pastebin'/><category term='cache'/><category term='multiline'/><category term='dynamic'/><category term='add'/><category term='recursive'/><category term='song'/><category term='load'/><category term='benchmark'/><category term='http'/><category term='curl'/><category term='IDE'/><category term='browsers'/><category term='string'/><category term='console'/><category term='buffer'/><category term='download'/><category term='programmer'/><category term='hMailServer'/><category term='php.ini'/><category term='else'/><category term='class'/><category term='script'/><category term='windows'/><category term='access'/><category term='statement'/><category term='head'/><category term='Size'/><category term='if'/><category term='PCRE'/><category term='crash'/><category term='bamcompiler'/><category term='speed'/><category term='extensions'/><category term='variable'/><category term='guide'/><category term='declaration'/><category term='tool'/><category term='php'/><category term='ajax'/><category term='constant'/><category term='header'/><category term='optimize'/><category term='chain'/><category term='validate'/><category term='files'/><category term='oop'/><category term='break'/><category term='expression'/><category term='website'/><category term='apache friends'/><category term='instance'/><category term='font'/><category term='regex'/><category term='jquery'/><category term='captcha'/><category term='imap'/><category term='microsoft'/><category term='server'/><category term='exit'/><category term='quotes'/><category term='ip address'/><category term='md5'/><category term='bundle'/><category term='data'/><category term='password'/><title type='text'>thephpcode</title><subtitle type='html'>thephpcode is where your PHP resources flow and you can find tips and tricks of PHP coding. Code snippets and examples are also provided. Best of PHP are included in thephpcode. Remember, if you have questions, do post a comment on the relevant post.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>65</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-7944191074413068043</id><published>2009-12-31T03:43:00.001Z</published><updated>2009-12-31T06:53:02.051Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='download'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='font'/><category scheme='http://www.blogger.com/atom/ns#' term='replacement'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>fontreplace - PHP/jQuery Font Replacement (FLIR)</title><content type='html'>Lately I was quite into web design and interface so much that I started exploring sIFR and FLIR. Yesterday I decided to develop a FLIR for PHP and jQuery.&lt;br /&gt;&lt;br /&gt;You can download the fontreplace package at: &lt;a href="http://www.mediafire.com/?0o511knwywm"&gt;http://www.mediafire.com/?0o511knwywm&lt;/a&gt; (122 kB, zip format).&lt;br /&gt;&lt;br /&gt;Features:&lt;ul&gt;&lt;li&gt;PHP 4.4.2 and above compatible&lt;/li&gt;&lt;li&gt;Uses jQuery Javascript Framework&lt;/li&gt;&lt;li&gt;Transparent background for CSS background support&lt;/li&gt;&lt;li&gt;Lightweight&lt;/li&gt;&lt;li&gt;Reads font color, font size, and font dynamically.&lt;/li&gt;&lt;li&gt;Detects whether user has font before loading from server&lt;/li&gt;&lt;li&gt;100% SEO Friendly and minimal code changes&lt;/li&gt;&lt;li&gt;Supports font color RGBA with alpha.&lt;/li&gt;&lt;li&gt;Tested working on IE7, IE8, FF 2.0, 3.0, 3.5, Safari (Win) 4.0 and Chrome 3.0, 4.0&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The demo and example is inside the zip file. Place the content of the zip file on a PHP-enabled server and run it on the browser.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-7944191074413068043?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.mediafire.com/?0o511knwywm' title='fontreplace - PHP/jQuery Font Replacement (FLIR)'/><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/7944191074413068043/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=7944191074413068043' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7944191074413068043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7944191074413068043'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/12/fontreplace-phpjquery-font-replacement.html' title='fontreplace - PHP/jQuery Font Replacement (FLIR)'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-9165358471385965802</id><published>2009-12-27T15:14:00.001Z</published><updated>2009-12-31T06:52:31.012Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='password'/><category scheme='http://www.blogger.com/atom/ns#' term='protection'/><category scheme='http://www.blogger.com/atom/ns#' term='md5'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>The Art of Password Protection in PHP</title><content type='html'>While I was working on some algorithm on PHP earlier on, I began to thought about the methods of password protection when I was still a novice in PHP, till now where I stand. Here's a little bit on how I went through the stages of password protection.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://img64.imageshack.us/img64/3589/artofpasswordprotection.jpg" target="_blank"&gt;&lt;img border="0" src="http://img64.imageshack.us/img64/3589/artofpasswordprotection.jpg" alt="The Art of Password Protection, MD5, SHA1, Salting, php code" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Of course my website wasn't hack and I wasn't that bad NOT to hash the password at all. When I started off building my first website, betaPod, I actually used MD5 for password to be hashed. Afterwhich, I learnt about how MD5 passwords can be rainbow-tabled and cracked, and came to know about what is called salting.&lt;br /&gt;&lt;br /&gt;Then when I thought that if salting is not enough, I came up with positions of the salt based on the password entered, which makes the hash very unique and secured.&lt;br /&gt;&lt;br /&gt;You can definitely use the code in the image.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-9165358471385965802?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/9165358471385965802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=9165358471385965802' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9165358471385965802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9165358471385965802'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/12/art-of-password-protection-in-php.html' title='The Art of Password Protection in PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2533370287375856151</id><published>2009-11-25T08:29:00.000Z</published><updated>2009-11-25T08:29:24.275Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='request'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><title type='text'>Issues with multiple requests on PHP</title><content type='html'>Again today I was answering questions on &lt;a href="http://stackoverflow.com/questions/1795372/multiple-requests-on-php"&gt;StackOverflow&lt;/a&gt; when I came across the question about not being able to load pages when downloading/loading large files.&lt;br /&gt;&lt;br /&gt;If you are using session, I suggest you use &lt;code&gt;session_write_close()&lt;/code&gt; before you output the file to the browser.&lt;br /&gt;&lt;br /&gt;This is because when the session is opened on one page, you cannot load another page until the session has been written and released. &lt;code&gt;session_write_close()&lt;/code&gt; is called automatically when your script ends, but because your outputting process takes time before your script end, your session file is locked and thus other pages cannot be viewed.&lt;br /&gt;&lt;br /&gt;However, if you are using different browser and/or system, it will be ok because the session file locked is unique to each SESSION ID.&lt;br /&gt;&lt;br /&gt;Look at: &lt;a href="http://php.net/manual/en/function.session-write-close.php"&gt;http://php.net/manual/en/function.session-write-close.php&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;However do take note that after &lt;code&gt;session_write_close()&lt;/code&gt;, you cannot call &lt;code&gt;session_start()&lt;/code&gt; or there will be a warning. Also if you make changes to &lt;code&gt;$_SESSION&lt;/code&gt;, it will not take effect.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2533370287375856151?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2533370287375856151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2533370287375856151' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2533370287375856151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2533370287375856151'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/11/issues-with-multiple-requests-on-php.html' title='Issues with multiple requests on PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8360105823426641897</id><published>2009-11-02T02:02:00.000Z</published><updated>2009-11-02T02:02:20.924Z</updated><title type='text'>Getting value from an object (or instance of a class) in PHP 5</title><content type='html'>Just earlier on I was working on the String class in the Samstyle PHP Framework. I was glad that I read the PHP manual and found this magical method in PHP5 OOP called __toString().&lt;br /&gt;&lt;br /&gt;Using __toString(), you can actually return a value for the object/instance of a class.&lt;br /&gt;&lt;br /&gt;See the example below:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;class MyClass{&lt;br /&gt;&lt;br /&gt;  function __construct(){&lt;br /&gt;    // constructor&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function __toString(){&lt;br /&gt;    // to String&lt;br /&gt;    return 5;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$inst = new MyClass();&lt;br /&gt;&lt;br /&gt;echo $inst; // echos 5&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;How powerful!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8360105823426641897?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8360105823426641897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8360105823426641897' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8360105823426641897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8360105823426641897'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/11/getting-value-from-object-or-instance.html' title='Getting value from an object (or instance of a class) in PHP 5'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-1609077332352331859</id><published>2009-10-30T16:14:00.001Z</published><updated>2009-11-10T23:34:15.417Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='class'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='chain'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='oop'/><title type='text'>jQuery-like chaining in PHP's Object Oriented Programming</title><content type='html'>It's interesting to see how object methods in PHP can be chained just like jQuery's chaining. &lt;br /&gt;&lt;br /&gt;jQuery's chaining:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$("div").children(".firstbtn").hide().fadeIn();&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In PHP, it is also possible to chain similarly. &lt;br /&gt;&lt;br /&gt;Using the &lt;a href="http://code.google.com/p/samstyle-php-framework/source/browse/trunk/class/string.class.php"&gt;string class&lt;/a&gt; from Samstyle PHP Framework, we can do chaining in PHP like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;echo $str-&gt;trim()-&gt;replace('a', 'b')-&gt;value();&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To do chaining in PHP, simply add a return statement at the end your methods where appropriate.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;return $this;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Advisable to only do this kind of chaining for Action methods, meaning to say that these methods are only doing actions which are not supposed to return value.&lt;br /&gt;&lt;br /&gt;Hope this helps!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-1609077332352331859?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/1609077332352331859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=1609077332352331859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1609077332352331859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1609077332352331859'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/10/jquery-like-chaining-in-phps-object.html' title='jQuery-like chaining in PHP&apos;s Object Oriented Programming'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5666507638406282942</id><published>2009-10-12T03:37:00.002+01:00</published><updated>2009-10-12T03:50:37.907+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='files'/><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='optimize'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='functions'/><title type='text'>file_get_contents() vs fread() - Speed Test and Benchmarking</title><content type='html'>File access is commonly found in any PHP application. Be it caching, or reading data from a file or what. Lately I've been wondering, whether the use of file_get_contents() over fread() is a good practice (i always prefer file_get_contents()).&lt;br /&gt;&lt;br /&gt;So this morning I ran a test between this 2 methods of reading a file. The script I used to run is at &lt;a href="http://thephpcode.pastebin.com/f2e84fab1"&gt;http://thephpcode.pastebin.com/f2e84fab1&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So here's the result from the tests of 5 runs:&lt;table style="width:100%;"&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;th&gt;fread() (seconds)&lt;/th&gt;&lt;th&gt;file_get_contents() (seconds)&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Mean&lt;/th&gt;&lt;td&gt;0.03674&lt;/td&gt;&lt;td&gt;0.01322&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Min&lt;/th&gt;&lt;td&gt;0.030710935592651&lt;/td&gt;&lt;td&gt;0.0098111629486084&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Max&lt;/th&gt;&lt;td&gt;0.04555082321167&lt;/td&gt;&lt;td&gt;0.016166925430298&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;So here it's clear that file_get_contents() is much faster than fread(), mainly because fread() consists of an overhead additional loop and several functions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5666507638406282942?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5666507638406282942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5666507638406282942' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5666507638406282942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5666507638406282942'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/10/filegetcontents-vs-fread-speed-test-and.html' title='file_get_contents() vs fread() - Speed Test and Benchmarking'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2187474133099312168</id><published>2009-10-10T09:45:00.003+01:00</published><updated>2009-10-10T10:25:53.812+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='optimize'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Bits'/><title type='text'>Using Bit Shifting to Divide / Multiply</title><content type='html'>To think of it, I rarely use bitwise operators in my coding - especially with all the convenience of other operators (can you imagine calculating bits whole day?).&lt;br /&gt;&lt;br /&gt;But seriously when I was reading on Bitwise operators, I realised that &lt;code&gt;($n / 2) == ($n &gt;&gt; 1)&lt;/code&gt;. So i tested out and...&lt;br /&gt;&lt;br /&gt;By shifting bits, we can actually do multiplication and division. But however, this is only true when ($n / $x) is still a integer.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$n = 1600;&lt;br /&gt;&lt;br /&gt;var_dump(($n / 2) == ($n &gt;&gt; 1));&lt;br /&gt;var_dump(($n / 4) == ($n &gt;&gt; 2));&lt;br /&gt;var_dump(($n / 8) == ($n &gt;&gt; 3));&lt;br /&gt;var_dump(($n / 16) == ($n &gt;&gt; 4));&lt;br /&gt;&lt;br /&gt;var_dump(($n * 2) == ($n &lt;&lt; 1));&lt;br /&gt;var_dump(($n * 4) == ($n &lt;&lt; 2));&lt;br /&gt;var_dump(($n * 8) == ($n &lt;&lt; 3));&lt;br /&gt;var_dump(($n * 16) == ($n &lt;&lt; 4));&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I ran some tests on which one is faster, and found that bitshifting is actually much faster.&lt;br /&gt;&lt;br /&gt;Here are the results:&lt;table style="width:100%;"&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;th&gt;Normal (seconds)&lt;/th&gt;&lt;th&gt;Bitshift (seconds)&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Mean&lt;/th&gt;&lt;td&gt;0.12407&lt;/td&gt;&lt;td&gt;0.10461&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Min&lt;/th&gt;&lt;td&gt;0.122979164124&lt;/td&gt;&lt;td&gt;0.104335069656&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Max&lt;/th&gt;&lt;td&gt;0.126028060913&lt;/td&gt;&lt;td&gt;0.105180025101&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;Post to the testing script: &lt;a href="http://thephpcode.pastebin.com/f1f6ec979"&gt;http://thephpcode.pastebin.com/f1f6ec979&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So when you do some simple math in programming, you know ways to speed things up.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2187474133099312168?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2187474133099312168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2187474133099312168' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2187474133099312168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2187474133099312168'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/10/using-bit-shifting-to-divide-multiply.html' title='Using Bit Shifting to Divide / Multiply'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8275919996767437212</id><published>2009-10-10T08:20:00.005+01:00</published><updated>2009-10-10T10:14:36.836+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='loop'/><category scheme='http://www.blogger.com/atom/ns#' term='iteration'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='optimize'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Pre vs Post Increment in PHP</title><content type='html'>Earlier on I was browsing Google Code, and I chanced upon &lt;a href="http://code.google.com/p/jspeed/"&gt;JSpeed&lt;/a&gt; - a javascript optimizer. I saw that they actually change post increments to pre-increments. I wondered why and thought I could &lt;a href="http://stackoverflow.com/questions/1546981/post-increment-vs-pre-increment-javascript-optimization"&gt;ask this on Stack Overflow&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;One theory came up to be "preincrement (++i) adds one to the value of i, then returns i; in contrast, i++ returns i then adds one to it, which in theory results in the creation of a temporary variable storing the value of i before the increment operation was applied". -- &lt;a href="http://physical-thought.blogspot.com/2008/11/pre-vs-post-increment-speed-test.html"&gt;http://physical-thought.blogspot.com/2008/11/pre-vs-post-increment-speed-test.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So I thought, what about PHP? &lt;br /&gt;&lt;br /&gt;I went on to test it on PHP with a FOR loop and I have the following code:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$time_start = microtime_float();&lt;br /&gt;&lt;br /&gt;for($i = 0; $i&lt;10000000;$i++){&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$time_end = microtime_float();&lt;br /&gt;$loadedin = (float)($time_end - $time_start);&lt;br /&gt;echo $loadedin.' s&lt;br/&gt;';&lt;br /&gt;&lt;br /&gt;$time_start = microtime_float();&lt;br /&gt;&lt;br /&gt;for($i = 0; $i&lt;10000000;++$i){&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$time_end = microtime_float();&lt;br /&gt;$loadedin = (float)($time_end - $time_start);&lt;br /&gt;echo $loadedin.' s&lt;br/&gt;';&lt;br /&gt;&lt;br /&gt;function microtime_float(){&lt;br /&gt;    list($usec, $sec) = explode(" ", microtime());&lt;br /&gt;    return ((float)$usec + (float)$sec);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Amazingly, pre-increment is much faster than post-increment in PHP. Look at the results:&lt;table style="width:100%;"&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;th&gt;Pre-inc (seconds)&lt;/th&gt;&lt;th&gt;Post-inc (seconds)&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Mean&lt;/th&gt;&lt;td&gt;0.68695&lt;/td&gt;&lt;td&gt;0.74147&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Min&lt;/th&gt;&lt;td&gt;0.685925960541&lt;/td&gt;&lt;td&gt;0.740597963333&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Max&lt;/th&gt;&lt;td&gt;0.68816781044&lt;/td&gt;&lt;td&gt;0.743010044098&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Thus I conclude that pre-increment is useful in for loops than post-increment. It is much faster through the iterations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8275919996767437212?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8275919996767437212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8275919996767437212' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8275919996767437212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8275919996767437212'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/10/pre-vs-post-increment-in-php.html' title='Pre vs Post Increment in PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8915789032443913137</id><published>2009-09-23T03:23:00.005+01:00</published><updated>2009-09-23T03:37:46.329+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cookie'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>Session Denial: session id contains illegal characters</title><content type='html'>This morning I woke up, went over to &lt;a href="http://stackoverflow.com/"&gt;StackOverflow&lt;/a&gt; (Yes I admit lately I've been quite active answering questions on SO) and I saw this question: &lt;a href="http://stackoverflow.com/questions/1463175/session-hijacking-or-attack"&gt;Session hijacking or attack?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The asker, &lt;a href="http://stackoverflow.com/users/125075/toto"&gt;Toto&lt;/a&gt;, saw these in his error logs:&lt;br /&gt;&lt;pre&gt;[22-Sep-2009 21:13:52] PHP Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/my_files/class.session.php on line 67 &lt;br /&gt;[22-Sep-2009 21:13:52] PHP Warning: Unknown: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 &lt;br /&gt;[22-Sep-2009 21:13:52] PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The first thing I thought before answering question was that obviously the user had tampered with the PHP session cookie (The cookie name is "PHPSESSID" by default). &lt;br /&gt;&lt;br /&gt;So what we can do to prevent these errors is to simply reset the ID whenever the session fails to start:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$ok = @session_start();&lt;br /&gt;if(!$ok){&lt;br /&gt;  session_regenerate_id(true); // replace the Session ID&lt;br /&gt;  session_start(); // restart the session (since previous start failed)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note that users tampering/changing the PHPSESSID to generate this error does not affect your server or read/write files on your server. It may be an attempt to generate great amount of log entries into your error logging file and so on. Thus with this solution, you can prevent such things from happening, yet allowing smooth load for normal users.&lt;br /&gt;&lt;br /&gt;this piece of security protection has been added to &lt;a href="http://code.google.com/p/samstyle-php-framework"&gt;Samstyle PHP Framework&lt;/a&gt; (after v1.2.11).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8915789032443913137?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8915789032443913137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8915789032443913137' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8915789032443913137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8915789032443913137'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/09/session-denial-session-id-contains.html' title='Session Denial: session id contains illegal characters'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-4554551636619446653</id><published>2009-09-04T15:47:00.003+01:00</published><updated>2009-09-15T13:45:32.147+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='statement'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='constant'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='variable'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>PHP speed up: Quote your strings</title><content type='html'>I've wanted to post this earlier, but i've been busy lately. So yeah, here's a tip off on how to speed things up for new or beginner php developers.&lt;br /&gt;&lt;br /&gt;You might have noticed, PHP error level by default is set to E_ALL &amp; ~E_NOTICE, which means all errors except notices are reported. &lt;br /&gt;&lt;br /&gt;Take a look at the following snippet:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$test = cool;&lt;br /&gt;echo $test;&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You might have noticed that it works fine. The output is still "cool". &lt;br /&gt;&lt;br /&gt;But when you set the error level to E_ALL, you get to see an additional line like this one:&lt;br /&gt;Notice: Use of undefined constant cool - assumed 'cool' in /public_html/quotestring.php on line 3&lt;br /&gt;&lt;br /&gt;This means what when the line "$test = cool;" is parsed, PHP actually look up whether a constant "cool" exists. If not, it will assume that it is the string "cool". This means that extra time is taken to find the constant.&lt;br /&gt;&lt;br /&gt;We ran a test to compare between quotes and no-quotes for a string, and also compared between &lt;a href="http://thephpcode.blogspot.com/2009/07/using-single-instead-of-double-quotes.html"&gt;double quotes and single quotes&lt;/a&gt;. the result was amazing (the output on browser):&lt;br /&gt;&lt;br /&gt;Notice: Use of undefined constant cool - assumed 'cool' in /public_html/quotestring.php on line 4&lt;br /&gt;cool&lt;br /&gt;0.000458002090454 s&lt;br /&gt;cool&lt;br /&gt;9.05990600586E-6 s&lt;br /&gt;cool&lt;br /&gt;8.10623168945E-6 s&lt;br /&gt;&lt;br /&gt;The first one is without quotes (look up constants then decide that it is a string). The 2nd one is using double quotes (look if there are variables or control characters to parse then output) and the last one is using single quotes (just output).&lt;br /&gt;&lt;br /&gt;The full PHP code for the test results can be found on Pastebin at the following link:&lt;br /&gt;&lt;a href="http://thephpcode.pastebin.com/f7bb6a1f9"&gt;http://thephpcode.pastebin.com/f7bb6a1f9&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So remember to quote your strings with single quotes and occasionally use double quotes to speed things up. I am Sam Yong, signing off.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-4554551636619446653?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/4554551636619446653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=4554551636619446653' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4554551636619446653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4554551636619446653'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/09/php-speed-up-quote-your-strings.html' title='PHP speed up: Quote your strings'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5471627759917395449</id><published>2009-08-31T15:42:00.004+01:00</published><updated>2009-08-31T15:57:43.558+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='GD'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>PHP GD: allow PHP to decide image type</title><content type='html'>It is at times quite troublesome having the need to detect what image type is the file, then decide which function (imagecreatefromjpeg, imagecreatefrompng or imagecreatefromgif) to use for the image. Well, here's a simple solution.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$src = "http://example.com/image.jpg";&lt;br /&gt;$image = imagecreatefile($src);&lt;br /&gt;&lt;br /&gt;function imagecreatefile($f){&lt;br /&gt;$content = file_get_contents($f);&lt;br /&gt;return imagecreatefromstring($content);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;That's a great and easy way. However, the bad thing is that there will be an overhead of a function and a large variable $content. Having the variable $content in the function scope allows the variable to be disposed at the end of the function, saving memory.&lt;br /&gt;&lt;br /&gt;To fix the large variable, you can do this instead:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$src = "http://example.com/image.jpg";&lt;br /&gt;$image = imagecreatefile($src);&lt;br /&gt;&lt;br /&gt;function imagecreatefile($f){&lt;br /&gt;return imagecreatefromstring(file_get_contents($f));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope it helps!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5471627759917395449?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5471627759917395449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5471627759917395449' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5471627759917395449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5471627759917395449'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/php-gd-allow-php-to-decide-image-type.html' title='PHP GD: allow PHP to decide image type'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5798199189178343764</id><published>2009-08-27T16:40:00.002+01:00</published><updated>2009-08-27T16:48:24.769+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='website'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>PHP new development site/manual</title><content type='html'>I was browsing the web earlier on, and I chanced upon one of the PHP website development server at &lt;a href="http://pb11.php.net/"&gt;http://pb11.php.net/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Some comments:&lt;br /&gt;the interface (UI) is definitely much better and everything's clearer.&lt;br /&gt;however, the layout and contents are much about the same from the current one.&lt;br /&gt;&lt;br /&gt;So you can try it out at &lt;a href="http://pb11.php.net/"&gt;http://pb11.php.net/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Take note that the mirror is unofficial and is not updated to the latest.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5798199189178343764?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5798199189178343764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5798199189178343764' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5798199189178343764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5798199189178343764'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/php-new-development-sitemanual.html' title='PHP new development site/manual'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-3952354342447666137</id><published>2009-08-24T01:22:00.004+01:00</published><updated>2009-08-24T01:28:51.967+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while'/><category scheme='http://www.blogger.com/atom/ns#' term='statement'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='loop'/><category scheme='http://www.blogger.com/atom/ns#' term='optimize'/><category scheme='http://www.blogger.com/atom/ns#' term='functions'/><title type='text'>Optimize your code: Keep functions out of statements!</title><content type='html'>It's always said that we should think out of the box. In any programming language, we should write functions out of certain statements statements.&lt;br /&gt;&lt;br /&gt;Consider this:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$arr = array(/* 10000 elements */);&lt;br /&gt;for($i = 0; $i &lt; count($arr); $i++){&lt;br /&gt; // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If you work this out slowly using a debugger or what, you would have noticed that count($arr) will be called for each iteration of the for loop! Each time you call count($arr), count() actually works out your array size and if your array is huge, the script will be stuck at this loop for a few seconds. &lt;br /&gt;&lt;br /&gt;So what about doing something like this?&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$arr = array(/* 10000 elements */);&lt;br /&gt;$l = count($arr);&lt;br /&gt;for($i = 0; $i &lt; $l; $i++){&lt;br /&gt; // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;Isn't this logically cleaner and faster in execution?&lt;br /&gt;&lt;br /&gt;This also applies to while loop.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-3952354342447666137?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/3952354342447666137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=3952354342447666137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3952354342447666137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3952354342447666137'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/optimize-your-code-keep-functions-out.html' title='Optimize your code: Keep functions out of statements!'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8315454173335428330</id><published>2009-08-24T00:34:00.003+01:00</published><updated>2009-08-24T00:58:15.456+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='end'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='test'/><title type='text'>PHP Arrays - End vs Indices</title><content type='html'>I've looked through the PHP Arrays function list lately while working on some php scripts that requires lots of interaction with Arrays. It came to me that the following 2 are the identical:&lt;br /&gt;&lt;br /&gt;$value = end($array);&lt;br /&gt;$value2 = $array[count($array)-1];&lt;br /&gt;&lt;br /&gt;But which is more efficient?&lt;br /&gt;&lt;br /&gt;In a test, I tested both with a 1000 elements array. A total of 5 tests were ran and an average of 0.00040926s for using end() and 0.00041699s for using $arr[count($arr)-1].&lt;br /&gt;&lt;br /&gt;That was only a single dimension array. Which means that all the elements are non-arrays. The moment i ran on a 2 dimensional array, the test results differ! Again I ran 5 tests, and an average of 0.00070285s for using end() and 0.00040769s for $arr[count($arr)-1].&lt;br /&gt;&lt;br /&gt;Why? end() has to move the internal pointer of the array all the way to the end of the array. However, end() is still useful for arrays whose keys are not numeric.&lt;br /&gt;&lt;br /&gt;The codes for the test can be found on pastebin at &lt;a href="http://thephpcode.pastebin.com/f7fa7d00c"&gt;http://thephpcode.pastebin.com/f7fa7d00c&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8315454173335428330?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8315454173335428330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8315454173335428330' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8315454173335428330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8315454173335428330'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/php-arrays-end-vs-indices.html' title='PHP Arrays - End vs Indices'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-9214857498125558159</id><published>2009-08-14T01:43:00.002+01:00</published><updated>2009-08-14T01:50:23.669+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='commit'/><category scheme='http://www.blogger.com/atom/ns#' term='rollback'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title type='text'>MySQL transaction (rollback+commit) - better with PHP</title><content type='html'>Lately I've been working on a project that has MySQL tables with relationship to each other. I have several functions that accesses the Database, and one function to call all these functions. However, I need to know that if one of the function that accesses the database fails, I need to do a rollback. &lt;br /&gt;&lt;br /&gt;Here's how we can do it:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;function addShop($shop){&lt;br /&gt;&lt;br /&gt;$ok = true;&lt;br /&gt;$ok = $ok &amp;&amp; mysql_query('START TRANSACTION');&lt;br /&gt;&lt;br /&gt;$ok = $ok &amp;&amp; shops_AddShop($shop);&lt;br /&gt;$ok = $ok &amp;&amp; ($shop['id'] = mysql_insert_id());&lt;br /&gt;$ok = $ok &amp;&amp; shops_UpdateCategories($shop);&lt;br /&gt;&lt;br /&gt;if($ok){&lt;br /&gt;mysql_query('COMMIT');&lt;br /&gt;}else{&lt;br /&gt;mysql_query('ROLLBACK');&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return $ok;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If one of the MySQL queries failed, I can do a rollback and reverse the appropriate changes. It's much better taking advantage of the &lt;a href="http://thephpcode.blogspot.com/2009/08/improving-and-speed-up-conditional.html"&gt;short circuit evaluation&lt;/a&gt; as talked about earlier on. &lt;br /&gt;&lt;br /&gt;In that case you will have a more stable application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-9214857498125558159?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/9214857498125558159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=9214857498125558159' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9214857498125558159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9214857498125558159'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/mysql-transaction-rollbackcommit-better.html' title='MySQL transaction (rollback+commit) - better with PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5134723078304153097</id><published>2009-08-14T01:06:00.004+01:00</published><updated>2009-08-20T02:06:07.552+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='dynamic'/><category scheme='http://www.blogger.com/atom/ns#' term='foreach'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='recursive'/><category scheme='http://www.blogger.com/atom/ns#' term='class'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><title type='text'>Getting function name in a function</title><content type='html'>I came to this time when I was doing recursive functions. I thought that if I change the function name, I will have to change the name again in the codes within the function. Consider the function below.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function a($v){&lt;br /&gt;$ret = array();&lt;br /&gt;  if(is_array($v))&lt;br /&gt;  {&lt;br /&gt;    foreach($v as $k){&lt;br /&gt;      $ret[] = a($k);&lt;br /&gt;    }&lt;br /&gt;  }else{&lt;br /&gt;    $ret = $v;&lt;br /&gt;  }&lt;br /&gt;  return $ret;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If i were to change the function name, and I forgot to change the one within the code, I will cause myself an error and debug intensively.&lt;br /&gt;&lt;br /&gt;However using backtrace, I am able to get the function name when inside a function. The function below enables you to get the function name when called. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function func_name(){&lt;br /&gt;$bt = debug_backtrace();&lt;br /&gt;$ret = '';&lt;br /&gt;if(isset($bt[1]) &amp;&amp; isset($bt[1]['function'])){&lt;br /&gt;$ret = $bt[1]['function'];&lt;br /&gt;}&lt;br /&gt;return $ret;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;So to get the first function working even after changing function name:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function a($v){&lt;br /&gt;$ret = array();&lt;br /&gt;  if(is_array($v))&lt;br /&gt;  {&lt;br /&gt;    $f = func_name();&lt;br /&gt;    foreach($v as $k){&lt;br /&gt;      $ret[] = $f($k);&lt;br /&gt;    }&lt;br /&gt;  }else{&lt;br /&gt;    $ret = $v;&lt;br /&gt;  }&lt;br /&gt;  return $ret;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And there you have it!&lt;br /&gt;&lt;br /&gt;This function was extracted from the php class (/class/php.class.php) of the fast and lightweight PHP framework - Samstyle PHP Framework 1.2.9 Alpha&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5134723078304153097?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5134723078304153097/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5134723078304153097' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5134723078304153097'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5134723078304153097'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/getting-function-name-in-function.html' title='Getting function name in a function'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-142635412005152681</id><published>2009-08-09T12:22:00.000+01:00</published><updated>2009-08-09T13:37:31.544+01:00</updated><title type='text'>Happy Birthday Singapore!</title><content type='html'>&lt;span style="font-weight:bold;font-size:140%;"&gt;We, the citizens of Singapore, pledge ourselves as one united people, regardless of race, language or religion, to build a democratic society, based on justice and equality, so as to achieve happiness, prosperity and progress for our nation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Happy Birthday Singapore!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-142635412005152681?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/142635412005152681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=142635412005152681' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/142635412005152681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/142635412005152681'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/happy-birthday-singapore.html' title='Happy Birthday Singapore!'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-4047378179740338190</id><published>2009-08-07T00:22:00.003+01:00</published><updated>2009-08-07T00:32:20.387+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='projects'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Calculations'/><title type='text'>Calculating Age using Birthday in PHP</title><content type='html'>Here's some food for the thoughts: calculating age using birthday in PHP. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function getAge($birthday){&lt;br /&gt;   $dt = strtotime($birthday);&lt;br /&gt;   // convert the birthday to a standard format (UNIX epoch)&lt;br /&gt;   $a = gmdate('Y') - gmdate('Y',$dt);&lt;br /&gt;   // find the difference of years&lt;br /&gt;   return $a; // return the age.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And here we have, a simple Age calculating function which is useful when displaying age on User profiles or calculating age restriction and so on. &lt;br /&gt;&lt;br /&gt;For example, you can put this against a movie age rating checker:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$bday = '1993-04-05';&lt;br /&gt;$age = getAge($bday);&lt;br /&gt;&lt;br /&gt;$movies = getPGMovies();&lt;br /&gt;&lt;br /&gt;if($age &gt;= 21){&lt;br /&gt;  // R21 and below can be watched&lt;br /&gt;  $movies= array_merge($movies,getR21Movies());&lt;br /&gt;}&lt;br /&gt;if($age &gt;= 18){&lt;br /&gt;  // M18 and below can be watched&lt;br /&gt;  $movies= array_merge($movies,getM18Movies());&lt;br /&gt;}&lt;br /&gt;if($age &gt;= 16){&lt;br /&gt;  // NC16 and below can be watched&lt;br /&gt;  $movies= array_merge($movies,getNC16Movies());&lt;br /&gt;}&lt;br /&gt;// display $movies&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-4047378179740338190?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/4047378179740338190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=4047378179740338190' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4047378179740338190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4047378179740338190'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/calculating-age-using-birthday-in-php.html' title='Calculating Age using Birthday in PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-3279832523379680283</id><published>2009-08-05T12:04:00.004+01:00</published><updated>2009-08-14T01:42:55.680+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='expression'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='if'/><category scheme='http://www.blogger.com/atom/ns#' term='condition'/><category scheme='http://www.blogger.com/atom/ns#' term='validate'/><title type='text'>Improving and Speed up Conditional Expressions</title><content type='html'>This is something cool and you can implement in your PHP scripts, and also you should make this a habit for most of your programming languages - and that is &lt;a href="http://en.wikipedia.org/wiki/Short-circuit_evaluation"&gt;Short Circuit Evaluation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Consider the following code:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function a(){&lt;br /&gt;echo 'a';&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function b(){&lt;br /&gt;echo 'b';&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(b() &amp;&amp; a()){&lt;br /&gt;echo 'c';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;When run, the output is only 'b'. Reason being that when the if statement is run, the checks from bracket then left to right. If the first expression evaluates into false, the second will not be run. &lt;br /&gt;&lt;br /&gt;Now take a look at the OR comparison operator.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function a(){&lt;br /&gt;echo 'a';&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function b(){&lt;br /&gt;echo 'b';&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(b() || a()){&lt;br /&gt;echo 'c';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This time, the output is 'bc'. Reason being that the expression in IF will be evaluated to the first true. if the first true is found, the rest will not be executed.&lt;br /&gt;&lt;br /&gt;This allows you to speed up your application. Think about the following code:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$url = htmlentities($_POST['url']);&lt;br /&gt;&lt;br /&gt;if($url == '' || validate::url($url)){&lt;br /&gt;echo 'URL is not valid.';&lt;br /&gt;}else{&lt;br /&gt;echo 'Valid URL provided';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It'll help to save time if the string is empty - since Short Circuit Evaluation parses that $url is empty, so it's a true and it won't bother to execute the rest of the expression.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-3279832523379680283?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/3279832523379680283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=3279832523379680283' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3279832523379680283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3279832523379680283'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/08/improving-and-speed-up-conditional.html' title='Improving and Speed up Conditional Expressions'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2044688692124564458</id><published>2009-07-30T06:37:00.004+01:00</published><updated>2009-08-01T05:50:24.884+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='functions'/><category scheme='http://www.blogger.com/atom/ns#' term='asp'/><title type='text'>Calling PHP functions from Javascript using/via AJAX</title><content type='html'>This has been quite a topic for some time - the ability for PHP functions to be called from Javascript. Well, yesterday I did it by implementing this feature into Samstyle PHP Framework. &lt;br /&gt;&lt;br /&gt;This is similar to ASP.NET AJAX Extension's Webservice, where you can directly call Methods in classes of your ASP.NET website.&lt;br /&gt;&lt;br /&gt;Download and experiment with this new feature at &lt;a href="http://code.google.com/p/samstyle-php-framework/"&gt;http://code.google.com/p/samstyle-php-framework/&lt;/a&gt;. Only available in the framework after version 1.2.6 BETA.&lt;br /&gt;&lt;br /&gt;But again remember, PHP is a server-side script, which shouldn't have access from a client-side script like javascript. here we're doing AJAX calls back to the server to call the function.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2044688692124564458?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2044688692124564458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2044688692124564458' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2044688692124564458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2044688692124564458'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/calling-php-functions-from-javascript.html' title='Calling PHP functions from Javascript using/via AJAX'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6366877203663397544</id><published>2009-07-26T04:37:00.004+01:00</published><updated>2009-07-26T04:45:01.930+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Color'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='GD'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>PHP: Generate random color code</title><content type='html'>Hello! today I was surfing the net again reading up articles when I came across this website which has a few codes on several uses. but their snippets were quite full of flaws and vulnerability.&lt;br /&gt;&lt;br /&gt;well, I am going to talk about one of their code snippets: &lt;a href="http://phpsnips.com/snippet.php?id=34"&gt;http://phpsnips.com/snippet.php?id=34&lt;/a&gt; - Generating random color code.&lt;br /&gt;&lt;br /&gt;Here's mine, a function that generates CSS-compatible colour code in hexadecimal:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function rand_colorCode(){&lt;br /&gt;$r = dechex(mt_rand(0,255)); // generate the red component&lt;br /&gt;$g = dechex(mt_rand(0,255)); // generate the green component&lt;br /&gt;$b = dechex(mt_rand(0,255)); // generate the blue component&lt;br /&gt;$rgb = $r.$g.$b;&lt;br /&gt;if($r == $g &amp;&amp; $g == $b){&lt;br /&gt;$rgb = substr($rgb,0,3); // shorter version&lt;br /&gt;}&lt;br /&gt;return '#'.$rgb;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$code = rand_colorCode();&lt;br /&gt;echo '&lt;span style="color:'.$code.'"&gt;This code is '.$code.'&lt;/span&gt;';&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Isn't this much better than the one posted at phpsnips.com? Note that this function doesn't utilize the functions in GD, but you can use the RGB in GD.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6366877203663397544?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6366877203663397544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6366877203663397544' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6366877203663397544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6366877203663397544'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/php-generate-random-color-code.html' title='PHP: Generate random color code'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6398925073530412689</id><published>2009-07-23T15:49:00.003+01:00</published><updated>2009-07-23T15:54:20.838+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='quotes'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='declaration'/><title type='text'>Using single instead of double quotes in PHP</title><content type='html'>Today I was reading up on some articles on the web when I suddenly gave thought about the codes I have always been doing.&lt;br /&gt;&lt;br /&gt;The other day I was talking to my friend about using single or double quotes, and I persisted on using single quotes instead of double quotes while writing string in PHP. My friend asked why: and here's why we use single quote (') instead of double (").&lt;br /&gt;&lt;br /&gt;When writing double (") quotes, PHP parses for variables and control characters (e.g. \n, \r, \t, ...) inside the string:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$str = "testing";&lt;br /&gt;echo "my string: $str";&lt;br /&gt;// outputs string(18) "my string: testing"&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Where possible, use single quotes (') to write strings:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$str = 'testing';&lt;br /&gt;echo 'my string: '.$str;&lt;br /&gt;// outputs string(18) "my string: testing"&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In conclusion: Single quotes speeds things up.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6398925073530412689?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6398925073530412689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6398925073530412689' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6398925073530412689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6398925073530412689'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/using-single-instead-of-double-quotes.html' title='Using single instead of double quotes in PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8781539686766161844</id><published>2009-07-20T16:46:00.003+01:00</published><updated>2009-07-20T16:50:41.434+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='http'/><category scheme='http://www.blogger.com/atom/ns#' term='library'/><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><category scheme='http://www.blogger.com/atom/ns#' term='html'/><title type='text'>Samstyle PHP Framework v1.2.0 released</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Finally Samstyle PHP Framework v1.2.0 is released!&lt;/span&gt; As promised, most features listed on the project home page are implemented in the v1.2.0 release.&lt;br /&gt;&lt;br /&gt;You can download a copy of the framework and start using it by visiting the project home page at &lt;a href="http://code.google.com/p/samstyle-php-framework/"&gt;http://code.google.com/p/samstyle-php-framework/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;it is the stable version and you can use it. &lt;br /&gt;&lt;br /&gt;Upcoming 1.2.1 will include a Form Javascript validator which you can create using the validator class.&lt;br /&gt;&lt;br /&gt;Should you need any help with framework, you can write a comment here, or on the Google code side, or email me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8781539686766161844?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://code.google.com/p/samstyle-php-framework/' title='Samstyle PHP Framework v1.2.0 released'/><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8781539686766161844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8781539686766161844' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8781539686766161844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8781539686766161844'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/samstyle-php-framework-v120-released.html' title='Samstyle PHP Framework v1.2.0 released'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-4754747926153650545</id><published>2009-07-19T14:43:00.003+01:00</published><updated>2009-07-20T00:04:03.546+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while'/><category scheme='http://www.blogger.com/atom/ns#' term='loop'/><category scheme='http://www.blogger.com/atom/ns#' term='apache friends'/><category scheme='http://www.blogger.com/atom/ns#' term='load'/><category scheme='http://www.blogger.com/atom/ns#' term='xampp'/><category scheme='http://www.blogger.com/atom/ns#' term='test'/><category scheme='http://www.blogger.com/atom/ns#' term='crash'/><title type='text'>PHP Code crashes Apache</title><content type='html'>Today i was reading up DoS and DDoS on Wikipedia when i came across this thing about Forkbomb (a kind of wabbit). So I tried it out on my own localhost server. &lt;br /&gt;&lt;br /&gt;This was what i wrote in the file:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;while(include(basename($_SERVER['PHP_SELF'])));&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Then I run the script on my browser. as expected, "apache.exe" crashes right after the script ran. The script will keep running and including itself, which in turns run more loops.&lt;br /&gt;&lt;br /&gt;However, the amazing thing is that, apache recovered itself and my localhost is able to run again. If you have noticed, apache actually runs on 2 processes, both "apache.exe". When the main process crashes, the secondary process detects this crash and then load the server again, thus preventing downtime.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-4754747926153650545?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/4754747926153650545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=4754747926153650545' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4754747926153650545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4754747926153650545'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/php-code-crashes-apache.html' title='PHP Code crashes Apache'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-540966046081830063</id><published>2009-07-14T08:57:00.004+01:00</published><updated>2009-07-25T03:34:26.396+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='captcha'/><category scheme='http://www.blogger.com/atom/ns#' term='images'/><category scheme='http://www.blogger.com/atom/ns#' term='hash'/><category scheme='http://www.blogger.com/atom/ns#' term='pastebin'/><category scheme='http://www.blogger.com/atom/ns#' term='guide'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='GD'/><title type='text'>PHP GD: Creating a security captcha in PHP</title><content type='html'>I was working on an application yesterday when I had to write a captcha security check on the form. So I came up with the following script to generate an image with random code. The script will also rotate the code a little in the image and randomize the position of the code on the image. a random background will also be selected (random background image should be 100px by 30px).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;&lt;br /&gt;// note that $_GET['k'] is a static key that you can enter when getting the image.&lt;br /&gt;// generate the key and store into session&lt;br /&gt;$_SESSION['captchasecurity'] = md5(mt_rand().time().$session_hash).$session_hash.md5($_GET['k'].mt_rand());&lt;br /&gt;// create a shorter key for display&lt;br /&gt;$key = dechex(crc32($_SESSION['captchasecurity']));&lt;br /&gt;&lt;br /&gt;// disable the client side caching&lt;br /&gt;header('Content-type: image/png');&lt;br /&gt;header('Cache-Control: max-age=0');&lt;br /&gt;header('Expires: '.gmdate('r',time()-3600*24*365));&lt;br /&gt;header('Pragma:');&lt;br /&gt;&lt;br /&gt;// randomize the background image&lt;br /&gt;$r = mt_rand(0,3);&lt;br /&gt;$captcha = imagecreatefrompng('img/captcha'.$r.'.png');&lt;br /&gt;&lt;br /&gt;$cl = mt_rand(0,50);&lt;br /&gt;$c = imagecolorallocate($captcha, $cl, $cl, $cl);&lt;br /&gt;$line = imagecolorallocate($captcha,233,239,239);&lt;br /&gt;&lt;br /&gt;$txtx = imagefontwidth(5) * strlen($key) +10;&lt;br /&gt;$txty = imagefontheight(5);&lt;br /&gt;&lt;br /&gt;$timg1 = imagecreate($txtx,$txtx);&lt;br /&gt;$ba = imagecolorallocatealpha($timg1,0, 0, 0,127);&lt;br /&gt;imagefilledrectangle($timg1, 0, 0, $txtx, $txtx, $ba);&lt;br /&gt;imagesavealpha($timg1, true);&lt;br /&gt;&lt;br /&gt;$tc = imagecolorallocate($timg1, $cl, $cl, $cl);&lt;br /&gt;imagestring($timg1, 5, 0, $txtx/2 - $txty/2, $key, $tc);&lt;br /&gt;&lt;br /&gt;$tca = imagecolorallocatealpha($timg1, 255, 255, 255,127);&lt;br /&gt;$timg = imagerotate($timg1, mt_rand(-5,5), $tca);&lt;br /&gt;imagesavealpha($timg, true);&lt;br /&gt;imagecopy($captcha, $timg, mt_rand(2,22), mt_rand(3,6), 0, $txtx/2 - $txty/2, $txtx, $txtx);&lt;br /&gt;&lt;br /&gt;// output the captcha image&lt;br /&gt;imagepng($captcha);&lt;br /&gt;&lt;br /&gt;// free up memory&lt;br /&gt;imagedestroy($timg);imagedestroy($timg1);&lt;br /&gt;imagedestroy($captcha);&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To check whether the code entered by the user against the one generated, simply do the following:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;// case sensitive check. CRC32 hash is in low case. &lt;br /&gt;if($_POST['captchacode'] != dechex(crc32($_SESSION['captchasecurity']))){&lt;br /&gt;// the code is wrong&lt;br /&gt;}else{&lt;br /&gt;// code is correct.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Get the full code on Pastebin: &lt;a href="http://thephpcode.pastebin.com/f21c1ed80"&gt;http://thephpcode.pastebin.com/f21c1ed80&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note that this captcha script has been tested to be successful on my localhost. I cannot guarantee 100% bot proof. You are advised to step up the security in your own application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-540966046081830063?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/540966046081830063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=540966046081830063' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/540966046081830063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/540966046081830063'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/php-gd-creating-security-captcha-in-php.html' title='PHP GD: Creating a security captcha in PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8664218920348640134</id><published>2009-07-13T14:44:00.004+01:00</published><updated>2009-07-13T15:02:21.263+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='statement'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='if'/><category scheme='http://www.blogger.com/atom/ns#' term='condition'/><category scheme='http://www.blogger.com/atom/ns#' term='else'/><category scheme='http://www.blogger.com/atom/ns#' term='benchmark'/><title type='text'>Speeding up conditional (IF/ELSE) statements</title><content type='html'>Do you know that conditional statements can be actually sped up if you use the appropriate statements and expressions?&lt;br /&gt;&lt;br /&gt;Take a look at the following 2 codes:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;if($test==5){&lt;br /&gt;print 't';&lt;br /&gt;}else{&lt;br /&gt;print 't2';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;($test == 5) ? print 't' : print 't2';&lt;br /&gt;// reason that i am using print is&lt;br /&gt;// because echo cannot be used.&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The second code block is actually faster than the first. I looped both codes 10 times and I got the following results: 4.31537628174E-5s for IF/ELSE (first code) and 1.50203704834E-5s for (second code) respectively. A difference of 2.8133392334E-5 seconds.&lt;br /&gt;&lt;br /&gt;However, the shortcoming of the second code block is that you can only put in one function in the condition at one time.&lt;br /&gt;&lt;br /&gt;Meaning to say you cannot do this:&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;($test == 5) ? print 't';$i++ : print 't2';&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;This will give a syntax error on PHP.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8664218920348640134?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8664218920348640134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8664218920348640134' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8664218920348640134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8664218920348640134'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/speeding-up-conditional-ifelse.html' title='Speeding up conditional (IF/ELSE) statements'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-1304988201969492128</id><published>2009-07-05T10:48:00.003+01:00</published><updated>2009-07-29T00:19:26.424+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='access'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='deny'/><category scheme='http://www.blogger.com/atom/ns#' term='include'/><title type='text'>Creating include-only PHP files</title><content type='html'>Sometimes you just want the files to be included, but not called directly. you might want to do this for security or what other reasons. here's the simple code:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;if name of the file requested is the same as the current file, the script will exit directly. place this at the top of the scripts you want to set include-only.&lt;br /&gt;&lt;br /&gt;However, take note that if the name of your included file is the same as your main file, it will get kicked out as well. As a developer, the convention is to name your files differently. e.g. users.php and users.inc.php&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-1304988201969492128?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/1304988201969492128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=1304988201969492128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1304988201969492128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1304988201969492128'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/creating-include-only-php-files.html' title='Creating include-only PHP files'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2866089707610294163</id><published>2009-07-05T10:19:00.004+01:00</published><updated>2009-07-05T10:25:46.863+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='iis'/><category scheme='http://www.blogger.com/atom/ns#' term='asp'/><title type='text'>Microsoft with PHP (on Windows IIS 7)</title><content type='html'>If you're thinking whether deploying PHP applications on your IIS or Windows Servers is possible - the answer is Yes.&lt;br /&gt;&lt;br /&gt;Lately Microsoft have shown their support for PHP through IIS 7 on their website (&lt;a href="http://www.microsoft.com/windowsserver/compare/php-on-windows/"&gt;http://www.microsoft.com/windowsserver/compare/php-on-windows/&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;To use PHP on IIS 7, simply add the PHP dynamic linking library into the Filter extensions of IIS 7 through the management console, you will be able to load PHP on IIS7.&lt;br /&gt;&lt;br /&gt;To learn more, you can start from &lt;a href="http://php.iis.net/"&gt;http://php.iis.net/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2866089707610294163?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2866089707610294163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2866089707610294163' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2866089707610294163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2866089707610294163'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/microsoft-with-php-on-windows-iis-7.html' title='Microsoft with PHP (on Windows IIS 7)'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-7338729567859482730</id><published>2009-07-05T05:48:00.004+01:00</published><updated>2009-07-11T02:02:18.544+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while'/><category scheme='http://www.blogger.com/atom/ns#' term='foreach'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='loop'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='test'/><category scheme='http://www.blogger.com/atom/ns#' term='benchmark'/><title type='text'>Arrays Loop Benchmarking: foreach vs while</title><content type='html'>Yes yes, i am current obsessed with loads of PHP speed tests on my local machine. But today I worked on something interesting: foreach vs while loops for Arrays.&lt;br /&gt;&lt;br /&gt;Remember one of my posts titled "&lt;a href="http://thephpcode.blogspot.com/2008/11/php-loop-benchmarking.html"&gt;PHP Loop Benchmarking - WHILE vs FOR&lt;/a&gt;"? It talks about your PHP scripts can be speed up using while loops instead of for loops?&lt;br /&gt;&lt;br /&gt;Well, for Arrays, this is not the case at all.&lt;br /&gt;&lt;br /&gt;In my test, i create an array with 100000 elements. Here's how I create the benchmarking array:&lt;br /&gt;&lt;code&gt;$a = array();&lt;br /&gt;while($i++ &lt; 100000){&lt;br /&gt;$a[] = dechex(crc32(mt_rand().time()));&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Then I move on to measure time taken to run through the array with a FOREACH loop:&lt;br /&gt;&lt;code&gt;foreach($a as $k){&lt;br /&gt;&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;The foreach run took 0.00826096534729 seconds.&lt;br /&gt;&lt;br /&gt;Next, I measure the time taken to run through the array, with a WHILE loop:&lt;br /&gt;&lt;code&gt;$z = -1;&lt;br /&gt;while($z++ &lt; count($a)){&lt;br /&gt;$k = $a[$z];&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;Amazingly, the run took 0.0426709651947 seconds - approximately 5 times slower than FOREACH loop.&lt;br /&gt;&lt;br /&gt;Then I moved on to optimize the while loop. Instead of calling the count() function at every step, I will store the number of elements into a variable before the loop.&lt;br /&gt;&lt;code&gt;$z = -1;&lt;br /&gt;$i = count($a);&lt;br /&gt;while($z++ &lt; $i){&lt;br /&gt;$k = $a[$z];&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;As expected, the run speeds up and it took 0.0160219669342 seconds. &lt;br /&gt;&lt;br /&gt;The reason behind the while loop being slow, is the fetching of element with "&lt;code&gt;$k = $a[$z];&lt;/code&gt;". Once i removed that line, the optimized while loop (3rd test run) ran at 0.00645399093628 seconds - 0.002 s faster than FOREACH.&lt;br /&gt;&lt;br /&gt;Note that the timings taken are an average of 5 runs spreaded across 5 mins (i.e. 1 run per minute) for the most accurate timings. Please note that the timings may differ from computer to computer. I am using Intel QuadCore 2.4GHz, 4GB RAM, Windows XP SP3, XAMPP 1.7.1, PHP 5.2.9.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-7338729567859482730?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/7338729567859482730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=7338729567859482730' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7338729567859482730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7338729567859482730'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/arrays-loop-benchmarking-foreach-vs.html' title='Arrays Loop Benchmarking: foreach vs while'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5030838170203837055</id><published>2009-07-04T17:22:00.005+01:00</published><updated>2009-07-05T05:33:06.805+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='hacker'/><category scheme='http://www.blogger.com/atom/ns#' term='load'/><category scheme='http://www.blogger.com/atom/ns#' term='cache'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='buffer'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Using include() in caching</title><content type='html'>Caching in a dynamically generated website is a great trick to speed things up. Can you imagine if 5000 users come to your web page at the same time, and you have to grab data from the database, manipulate, validate then output the data  &lt;span style="font-weight:bold;"&gt;5000 times&lt;/span&gt;? That'd take a great load of time.&lt;br /&gt;&lt;br /&gt;Instead, when using caching, the server load will be greatly reduced and thus speeding things up. The 5000 users come to your webpage at the same time, only the first user grabs data from the database, manipulate, validate, output then save the output. The following 4999 users just have to grab the output from the cache and that's it!&lt;br /&gt;&lt;br /&gt;I was working on the caching module of Samstyle PHP Framework today. Googling around, I discovered that many examples on PHP output caching out there on the web uses include() to retrieve and display data from the cache.&lt;br /&gt;&lt;br /&gt;Some articles are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a target="_blank" href="http://www.theukwebdesigncompany.com/articles/php-caching.php"&gt;PHP Caching to Speed up Dynamically Generated Sites&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a target="_blank" href="http://simonwillison.net/2003/May/5/cachingWithPHP/"&gt;Instant Caching with PHP&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;This is very dangerous. Any executable PHP code in the cached file will also be executed as you are using an include(). Malicious code may be injected into the cache by exploiting this security leak.&lt;br /&gt;&lt;br /&gt;For example if you are doing a search page. And the user is able to enter some search keywords into the box. He/she hits enter and the query is run. When you are displaying the result, you also display what the user has searched for. So the query is displayed.&lt;br /&gt;&lt;br /&gt;Everything is cached - including the query that the user has entered. Think about it, what if the user had entered PHP codes into the query box and hit enter. Then he/she refreshes the page - the code gets executed!&lt;br /&gt;&lt;br /&gt;The user can then use unlink() to delete all the files on your server and so on. &lt;br /&gt;&lt;br /&gt;Instead of using include() for reading cache file, you could have directly used readfile(), which reads the file and writes directly to output buffer. This means that no code will be executed in the cache file on the server.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5030838170203837055?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5030838170203837055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5030838170203837055' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5030838170203837055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5030838170203837055'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/using-include-in-caching.html' title='Using include() in caching'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2257919548076476048</id><published>2009-07-04T01:29:00.002+01:00</published><updated>2009-07-04T01:32:43.817+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='framework'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>Samstyle PHP Framework</title><content type='html'>Hi all!&lt;br /&gt;&lt;br /&gt;I am opening my framework to be open source. More details of it can be found at &lt;a href="http://code.google.com/p/samstyle-php-framework/"&gt;http://code.google.com/p/samstyle-php-framework/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The framework aims to be the fastest, easiest, scalable, easily deployable and most expandable framework for PHP that is available. Since it is open source, anyone can contribute to it by branching it. It has MVC and an extension over the model.&lt;br /&gt;&lt;br /&gt;If you wish to become a committer/member working on Samstyle PHP Framework, do contact me.&lt;br /&gt;&lt;br /&gt;Cheers&lt;br /&gt;Sam Yong&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2257919548076476048?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2257919548076476048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2257919548076476048' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2257919548076476048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2257919548076476048'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/samstyle-php-framework.html' title='Samstyle PHP Framework'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-4879025165373892507</id><published>2009-07-03T10:12:00.004+01:00</published><updated>2009-07-15T04:24:32.496+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='declaration'/><category scheme='http://www.blogger.com/atom/ns#' term='functions'/><title type='text'>PHP Functions - too dynamic?</title><content type='html'>Today I was working on an application, where I found it strange when my application function is not working as I wanted it to be.&lt;br /&gt;&lt;br /&gt;After a quick debug, I found out that it's because:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;func($param1,$param2,$param3); // the way i am calling the function&lt;br /&gt;&lt;br /&gt;function func($params){&lt;br /&gt;// i declared func this way, and accepted $params as array of parameters 1, 2 and 3.&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Ended up, function "func" read in only $param1 and not $param2 and $param3. On top of that, it does not display any error or warning.&lt;br /&gt;&lt;br /&gt;Note that when calling any PHP functions, you can specify additional parameters/arguments than what is defined in declaration. However, you cannot specify number of parameters less than declared.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-4879025165373892507?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/4879025165373892507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=4879025165373892507' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4879025165373892507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4879025165373892507'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/php-functions-too-dynamic.html' title='PHP Functions - too dynamic?'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-3048408521349314568</id><published>2009-07-03T10:00:00.004+01:00</published><updated>2009-07-29T13:02:35.534+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='curl'/><category scheme='http://www.blogger.com/atom/ns#' term='extensions'/><category scheme='http://www.blogger.com/atom/ns#' term='library'/><category scheme='http://www.blogger.com/atom/ns#' term='hash'/><category scheme='http://www.blogger.com/atom/ns#' term='apache friends'/><category scheme='http://www.blogger.com/atom/ns#' term='xampp'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='php.ini'/><category scheme='http://www.blogger.com/atom/ns#' term='dll'/><title type='text'>Enabling extensions/dll in PHP of XAMPP</title><content type='html'>It has become common that as we work on our application locally, we might need to enable more and more extensions. For example, cURL and hash, they are not enabled on XAMPP's PHP by default. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;What are extensions?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Extensions are DLLs (dynamically linked libraries) written in C and compiled, and that are added, enabled, disabled into PHP through the PHP configuration file php.ini. These extensions do not change your coding experience or the language, but in fact, they add on new sets of functions to your existing functions in PHP.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To enable the dynamic extensions you need in PHP, simply go to C:\xampp\apache\bin, open up php.ini, and search for "Windows Extensions" or "extension=".&lt;br /&gt;&lt;br /&gt;Then, find the entry where your required DLL is written. If a ";" is at the front, remove it - that will uncomment the line so that PHP loads the extension.&lt;br /&gt;&lt;br /&gt;Lastly, restart Apache server using XAMPP Control Panel and you should be able to use functions from your extension already.&lt;br /&gt;&lt;br /&gt;Note that this works for any other servers as well as long as you are using PHP. but the configuration file might differ.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-3048408521349314568?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/3048408521349314568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=3048408521349314568' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3048408521349314568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3048408521349314568'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/enabling-extensionsdll-in-php-of-xampp.html' title='Enabling extensions/dll in PHP of XAMPP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-9119064122964269824</id><published>2009-07-02T15:43:00.005+01:00</published><updated>2009-07-11T02:02:26.091+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='foreach'/><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='methods'/><category scheme='http://www.blogger.com/atom/ns#' term='class'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><category scheme='http://www.blogger.com/atom/ns#' term='benchmark'/><title type='text'>Array vs Class - which is better?</title><content type='html'>The other day I was discussing with my friend and we talked about Array and Classes. of course in Samstyle PHP Framework, I actually dropped the usage of classes. There are reasons why I went for arrays instead of classes.&lt;br /&gt;&lt;br /&gt;With the help of &lt;span style="font-weight:bold;"&gt;PHP: Arrays vs. Objects - 't Bijstere spoor&lt;/span&gt; (&lt;a href="http://www.rooftopsolutions.nl/article/148"&gt;http://www.rooftopsolutions.nl/article/148&lt;/a&gt;), I actually wrote a piece of code that tests for memory usage of Array and Class.&lt;br /&gt;&lt;br /&gt;For Array memory testing:&lt;br /&gt;&lt;code&gt;   $data = array();&lt;br /&gt;echo memory_get_usage().' b&amp;lt;br/&amp;gt;';&lt;br /&gt;&lt;br /&gt;   for($i=0;$i&lt;1000;$i++) {&lt;br /&gt;&lt;br /&gt;       $data[] = array(&lt;br /&gt;            'property1' =&gt; md5(microtime()),&lt;br /&gt;            'property2' =&gt; md5(microtime()),&lt;br /&gt;            'property3' =&gt; md5(microtime()),&lt;br /&gt;       );&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;echo memory_get_usage().' b&amp;lt;br/&amp;gt;'; &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The memory usage difference was &lt;span style="font-weight:bold;"&gt;549064 bytes&lt;/span&gt; for using Arrays.&lt;br /&gt;&lt;br /&gt;For Class memory testing:&lt;br /&gt;&lt;code&gt;   class Test {&lt;br /&gt;&lt;br /&gt;       public $property1;&lt;br /&gt;       public $property2;&lt;br /&gt;       public $property3;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;echo memory_get_usage().' b&amp;lt;br/&amp;gt;';&lt;br /&gt;&lt;br /&gt;   for($i=0;$i&lt;1000;$i++) {&lt;br /&gt;&lt;br /&gt;       $test = new Test();&lt;br /&gt;       $test-&gt;property1 = md5(microtime());&lt;br /&gt;       $test-&gt;property2 = md5(microtime());&lt;br /&gt;       $test-&gt;property3 = md5(microtime());&lt;br /&gt;       $data[] = $test;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;echo memory_get_usage().' b&amp;lt;br/&amp;gt;'; &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The memory usage difference was &lt;span style="font-weight:bold;"&gt;573224 bytes&lt;/span&gt; for using Classes.&lt;br /&gt;&lt;br /&gt;Arrays actually has a less memory usage (549064 bytes to create 1000 arrays) compared to Classes (573224 bytes to create 1000 classes).&lt;br /&gt;&lt;br /&gt;Well, in terms of speed, we did the same thing, except measuring time. Arrays (0.0161869525909s to loop 1000 times) are actually faster compared to classes (0.0189130306244s to loop 1000 times).&lt;br /&gt;&lt;br /&gt;Therefore in terms of speed and performance, Arrays won over Classes.&lt;br /&gt;&lt;br /&gt;On top of that, Arrays allows you to use the FOREACH($ARR as $KEY =&gt; $VALUE) loop, which is easier and better for us programmer, instead of statically writing each property of the class.&lt;br /&gt;&lt;br /&gt;However, Arrays do not support instances, unlike Classes. Classes can define methods which allows the code to look cleaner and more efficient.&lt;br /&gt;&lt;br /&gt;Note that the timings taken are an average of 5 runs spreaded across 5 mins (i.e. 1 run per minute) for the most accurate timings. Please note that the timings may differ from computer to computer. I am using Intel QuadCore 2.4GHz, 4GB RAM, Windows XP SP3, XAMPP 1.7.1, PHP 5.2.9.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-9119064122964269824?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/9119064122964269824/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=9119064122964269824' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9119064122964269824'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9119064122964269824'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/07/array-vs-class-which-is-better.html' title='Array vs Class - which is better?'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2854306604768718472</id><published>2009-06-29T11:16:00.003+01:00</published><updated>2009-07-11T02:02:32.933+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while'/><category scheme='http://www.blogger.com/atom/ns#' term='echo'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='output'/><category scheme='http://www.blogger.com/atom/ns#' term='test'/><category scheme='http://www.blogger.com/atom/ns#' term='buffer'/><category scheme='http://www.blogger.com/atom/ns#' term='benchmark'/><title type='text'>Echo vs Output buffer</title><content type='html'>Here I am again. Lately i've been working on my framework - &lt;a href="http://code.google.com/p/samstyle-php-framework/"&gt;Samstyle PHP Framework&lt;/a&gt; - and now i am here to share with you about Echo versus Output Buffering.&lt;br /&gt;&lt;br /&gt;Just today I have tested and proved why output buffering then echo is always better than a direct echo. For this, i created a script that will first run:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$u = 10000;&lt;br /&gt;while($u-- &gt; 0){echo 'testing 123&amp;lt;br/&amp;gt;';}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;then next run the following:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$u = 10000;&lt;br /&gt;$b = '';&lt;br /&gt;while($u-- &gt; 0){$b.= 'testing 123&amp;lt;br/&amp;gt;';}&lt;br /&gt;echo $b;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;(Psst for reasons why I used a while loop over for loop, look at: )&lt;br /&gt;and then I calculated time taken to execute each of the code.&lt;br /&gt;&lt;br /&gt;I found that buffering the output in a variable first (in this case $b) then output, is much faster compared to direct output.&lt;br /&gt;&lt;br /&gt;For the first run, it took 0.183017015457 seconds. As for the second run, it took 0.0580809116364 seconds. That's an amazing speed improvement of more than 1/3 of the original code.&lt;br /&gt;&lt;br /&gt;Even running only 100 times instead of 10000 times, there's still a significant difference between the speed of the 2 runs. Try that now!&lt;br /&gt;&lt;br /&gt;Note that the timings taken are an average of 5 runs spreaded across 5 mins (i.e. 1 run per minute) for the most accurate timings. Please note that the timings may differ from computer to computer. I am using Intel QuadCore 2.4GHz, 4GB RAM, Windows XP SP3, XAMPP 1.7.1, PHP 5.2.9.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2854306604768718472?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2854306604768718472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2854306604768718472' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2854306604768718472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2854306604768718472'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/06/echo-vs-output-buffer.html' title='Echo vs Output buffer'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-405922797649131786</id><published>2009-06-23T09:05:00.003+01:00</published><updated>2009-06-29T13:43:15.771+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php2bin'/><category scheme='http://www.blogger.com/atom/ns#' term='tool'/><category scheme='http://www.blogger.com/atom/ns#' term='download'/><category scheme='http://www.blogger.com/atom/ns#' term='bamcompiler'/><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='GD'/><category scheme='http://www.blogger.com/atom/ns#' term='php2exe'/><category scheme='http://www.blogger.com/atom/ns#' term='console'/><title type='text'>Image Comparison Tool</title><content type='html'>Remember the Image Comparison script i had mentioned earlier on? I have compiled it into a Windows console application.&lt;br /&gt;&lt;br /&gt;Download the free Image Comparison Tool:&lt;br /&gt;&lt;iframe scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:240px;height:66px;margin:3px;padding:0;border:1px solid #dde5e9;background-color:#ffffff;" src="http://cid-4b65336ce36548ef.skydrive.live.com/embedrowdetail.aspx/Public/imgcmp.zip"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;Usage: imgcmp image1.ext image2.ext&lt;br /&gt;&lt;br /&gt;Cheers to all! It will return in percentage as output on the console.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-405922797649131786?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/405922797649131786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=405922797649131786' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/405922797649131786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/405922797649131786'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/06/image-comparison-tool.html' title='Image Comparison Tool'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8089511518406093884</id><published>2009-06-21T12:17:00.002+01:00</published><updated>2009-06-21T12:31:08.975+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Color'/><category scheme='http://www.blogger.com/atom/ns#' term='images'/><category scheme='http://www.blogger.com/atom/ns#' term='library'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='GD'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Bits'/><title type='text'>PHP GD: Getting pixel information</title><content type='html'>Hello there! It's Sam Yong here again. Earlier on I was developing a PHP script for comparing 2 images and find out their similarity. I was rather successful with it.&lt;br /&gt;&lt;br /&gt;Well, today I am going to discuss about PHP's GD library - how to get the Red, Green, Blue information of a pixel of an image resource. &lt;br /&gt;&lt;br /&gt;Firstly, when we want to get a pixel's color information from an image, we use &lt;code&gt;imagecolorat&lt;/code&gt;. The function returns a 24 bit RGB information in Integer. So by shifting the bits, you will be able to get the individual Red, Green, Blue components of the RGB information in integer. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;// retrieve rgb info from $img resource at ($x,$y)&lt;br /&gt;$rgb = &lt;a href="http://www.php.net/manual/en/function.imagecolorat.php"&gt;imagecolorat&lt;/a&gt;($img,$x,$y);&lt;br /&gt;&lt;br /&gt;if($rgb){&lt;br /&gt;$r = ($rgb &gt;&gt; 16) &amp; 0xFF;&lt;br /&gt;$g = ($rgb &gt;&gt; 8) &amp; 0xFF;&lt;br /&gt;$b = $rgb &amp; 0xFF;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note that each color has a value that runs from 0 to 255 (8 bit).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8089511518406093884?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8089511518406093884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8089511518406093884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8089511518406093884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8089511518406093884'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/06/php-gd-getting-pixel-information.html' title='PHP GD: Getting pixel information'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5102823544603201684</id><published>2009-06-19T07:28:00.005+01:00</published><updated>2009-06-21T12:31:41.099+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='variable'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>Variable Variables</title><content type='html'>Have you really thought about how dynamic PHP can be? Well seriously if you haven't, check this out! Variable variables.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$a = 'hello';&lt;br /&gt;$hello = 'hello world!';&lt;br /&gt;echo $$a;&lt;br /&gt;&lt;br /&gt;// outputs as "hello world!"&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Why? $$a is evaluated automatically by PHP into $hello, since $a is 'hello'.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5102823544603201684?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5102823544603201684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5102823544603201684' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5102823544603201684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5102823544603201684'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/06/variable-variables.html' title='Variable Variables'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8750146976845507018</id><published>2009-03-25T23:34:00.005Z</published><updated>2009-09-01T15:24:58.280+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='pop3'/><category scheme='http://www.blogger.com/atom/ns#' term='smtp'/><category scheme='http://www.blogger.com/atom/ns#' term='mail'/><category scheme='http://www.blogger.com/atom/ns#' term='imap'/><category scheme='http://www.blogger.com/atom/ns#' term='xampp'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='hMailServer'/><title type='text'>Setting up local Mail (SMTP, POP3, IMAP) Server on XAMPP</title><content type='html'>While I was doing a PHP project on my localhost using XAMPP, i realised I needed a local mail server in order to send out mails from my own workstation for testing. To come to think of it, XAMPP provides MercuryMail - but it's user-unfriendly interface and low level support makes it very difficult to use.&lt;br /&gt;&lt;br /&gt;Previously when I was on Windows XP Professional Edition, I was able to install IIS with SMTP server and configure as such for PHP on Apache (XAMPP) to send out mails via IIS SMTP mail server.&lt;br /&gt;&lt;br /&gt;However when I shifted to Windows Vista Home Premium, i realised that IIS7 do not come with a SMTP mail server. So I tried finding an alternative mail server for my computer.&lt;br /&gt;&lt;br /&gt;I remembered about a software called &lt;a target="_blank" href="http://hmailserver.com/"&gt;hMailServer&lt;/a&gt; which I used on a website server. It was quite easy to use and have great UI. So i decided to give it a try. I downloaded and installed hMailServer.&lt;br /&gt;&lt;br /&gt;To configure your computer to properly send mail, you need to do the following:&lt;br /&gt;1) When you first open hMailServer Administrator, you need to add a new domain.&lt;br /&gt;2) Click on the "Add Domain ..." button at the Welcome page. &lt;br /&gt;3) Under the domain text field, enter your computer's IP, in this case it should be 127.0.0.1.&lt;br /&gt;4) Click on the Save button.&lt;br /&gt;5) Go to Settings&gt;Protocols&gt;SMTP and select "Delivery of Email" tab&lt;br /&gt;6) Enter "localhost" in the localhost name field.&lt;br /&gt;7) Click on the Save button.&lt;br /&gt;&lt;br /&gt;It should then be able to send mail.&lt;br /&gt;&lt;br /&gt;If you need to send mail using a FROM addressee of another computer, you need to allow deliveries from External to External accounts. To do that, follow these steps:&lt;br /&gt;1) Go to Settings&gt;Advanced&gt;IP Ranges and double click on "My Computer" which should have IP address of 127.0.0.1&lt;br /&gt;2) Check the Allow Deliveries from External to External accounts checkbox.&lt;br /&gt;3) Save settings using Save button.&lt;br /&gt;&lt;br /&gt;Now you should be able to send email from your PHP project using mail() function or your ASP.NET application via your own computer's SMTP mail server.&lt;br /&gt;&lt;br /&gt;UPDATE - 1st September 09&lt;br /&gt;I was working with local application to send mail when I debugged that Windows Live Hotmail (the email from Microsoft) has denied all emails coming from dynamic IPs (which most residential computers are using). So this means that emails from your localhost cannot be sent to Hotmail accounts (e.g. @hotmail.com, @live.com ...). A workaround for this is for you have a Gmail account, and follow the following steps:&lt;br /&gt;&lt;br /&gt;1) Go to Settings&gt;Protocols&gt;SMTP and select "Delivery of Email" tab&lt;br /&gt;2) Enter "smtp.gmail.com" in the Remote Host name field.&lt;br /&gt;3) Enter "465" as the port number&lt;br /&gt;4) Check "Server requires authentication"&lt;br /&gt;5) Enter your Google Mail address in the Username field&lt;br /&gt;6) Enter your Google Mail password in the password field.&lt;br /&gt;7) Check "Use SSL"&lt;br /&gt;&lt;br /&gt;and save. it will relay to Google Mail and then be sent to the intended recipients. Take note that whatever you write in the From header will be replaced with your gmail address. eg. you wrote From: user@example.com, it will be replaced by Google to example@gmail.com. For more about this see &lt;a href="http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server"&gt;http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8750146976845507018?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8750146976845507018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8750146976845507018' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8750146976845507018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8750146976845507018'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/03/setting-up-local-mail-smtp-pop3-imap.html' title='Setting up local Mail (SMTP, POP3, IMAP) Server on XAMPP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-3697442914288873301</id><published>2009-02-15T00:10:00.002Z</published><updated>2009-02-15T00:27:56.022Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='output'/><category scheme='http://www.blogger.com/atom/ns#' term='variable'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='buffer'/><category scheme='http://www.blogger.com/atom/ns#' term='programmer'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title type='text'>PHP Output Buffering</title><content type='html'>wow, it's been awhile already but i'm back to post more PHP-related articles. lately i'm busy working on another project for Microsoft Imagine Cup - the round 1 ends on 27 Feb 09. &lt;br /&gt;&lt;br /&gt;Normally when most PHP programmers codes their PHP application, they'll have something like this - PHP in HTML:&lt;code&gt;&lt;br /&gt;&amp;lt;ul&amp;gt;&lt;br /&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;?php &lt;a href="http://php.net/function.echo"&gt;echo&lt;/a&gt; $tabs[0]; ?&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;?php &lt;a href="http://php.net/function.echo"&gt;echo&lt;/a&gt; $tabs[1]; ?&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;?php &lt;a href="http://php.net/function.echo"&gt;echo&lt;/a&gt;  $tabs[2]; ?&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Why not have your HTML codes buffered in your own PHP variable and process it before echo to output like this?&lt;code&gt;&lt;br /&gt;&amp;lt;?php &lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt;  '&amp;lt;ul&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt;  '&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;'.$tabs[0].'&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt;  '&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;'.$tabs[1].'&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt;  '&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;'.$tabs[2].'&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt;  '&amp;lt;/ul&amp;gt;';';&lt;br /&gt;&lt;br /&gt;echo $buffer;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Also when you buffer using the 2nd method, you can reduce the need of removing whitespaces and newline characters in the HTML output, thus increasing the efficiency of your application.&lt;br /&gt;&lt;br /&gt;With the $buffer variable, you can also post-process the buffer by applying custom tags. an example:&lt;code&gt;&lt;br /&gt;&amp;lt;?php &lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt; '&amp;lt;ul&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt; '&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;$tab1$&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt; '&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;$tab2$&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt; '&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;&amp;lt;$tab3$&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;';&lt;br /&gt;$buffer &lt;a href="http://php.net/manual/en/language.operators.string.php"&gt;.=&lt;/a&gt; '&amp;lt;/ul&amp;gt;';';&lt;br /&gt;&lt;br /&gt;&lt;a href="http://php.net/function.echo"&gt;echo&lt;/a&gt; &lt;a href="http://php.net/str-ireplace"&gt;str_ireplace&lt;/a&gt;(&lt;a href="http://php.net/function.array"&gt;array&lt;/a&gt;('&lt;$tab1$&gt;','&lt;$tab2$&gt;','&lt;$tab3$&gt;'),&lt;a href="http://php.net/function.array"&gt;array&lt;/a&gt;($tab[0],$tab[1],$tab[2]),$buffer);&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Isn't that great? Hope this helps for you. I am Sam Yong, your multi-disciplinary software developer major in PHP, signing off.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-3697442914288873301?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/3697442914288873301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=3697442914288873301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3697442914288873301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3697442914288873301'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/02/php-output-buffering.html' title='PHP Output Buffering'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-1411234156117200646</id><published>2009-02-03T14:07:00.000Z</published><updated>2009-02-03T14:16:20.724Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='multiline'/><category scheme='http://www.blogger.com/atom/ns#' term='trim'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>Trimming each line: trim() function</title><content type='html'>Just a few days ago, i ran into this problem of needing to trim off spaces in front and behind of each line of a string with multiline. so i came up with this simple function to do the job.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function trimlines($s,$t){&lt;br /&gt;$e = explode("\n",$s);&lt;br /&gt;foreach($e as $i =&gt; $a){$e[i] = trim($a,$t)}&lt;br /&gt;return implode("\n",$e);&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Optimized-for-speed version:&lt;br /&gt;&lt;code&gt;function trimlines($s,$t){&lt;br /&gt;$e = explode("\n",$s);$z = count($e);&lt;br /&gt;while($z--&gt;0){$e[z] = trim($e[z],$t)}&lt;br /&gt;return implode("\n",$e);&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;simple, ain't it?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-1411234156117200646?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/1411234156117200646/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=1411234156117200646' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1411234156117200646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1411234156117200646'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/02/trimming-each-line-trim-function.html' title='Trimming each line: trim() function'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-7388908352526302657</id><published>2009-01-13T09:29:00.000Z</published><updated>2009-01-13T09:52:49.576Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='http'/><category scheme='http://www.blogger.com/atom/ns#' term='pastebin'/><category scheme='http://www.blogger.com/atom/ns#' term='ip address'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>PHP: Getting Secondary Internet Protocol (IP) Address</title><content type='html'>You'll probably get the Remote IP Address of your users by using the server variable $_SERVER['REMOTE_ADDR']. However, if your users are being proxy servers or using dynamic IP address, you won't get the actual IP Address of your users using $_SERVER['REMOTE_ADDR'].&lt;br /&gt;&lt;br /&gt;Probably you need the following code to help you to get the actual IP address of your users.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function getIP() {&lt;br /&gt;  $IP = '';&lt;br /&gt;if (getenv('HTTP_CLIENT_IP')) {$IP =getenv('HTTP_CLIENT_IP');}&lt;br /&gt;elseif (getenv('HTTP_X_FORWARDED_FOR')) {$IP =getenv('HTTP_X_FORWARDED_FOR');}&lt;br /&gt;elseif (getenv('HTTP_X_FORWARDED')) {$IP =getenv('HTTP_X_FORWARDED');}&lt;br /&gt;elseif (getenv('HTTP_FORWARDED_FOR')) {$IP =getenv('HTTP_FORWARDED_FOR');}&lt;br /&gt;elseif (getenv('HTTP_FORWARDED')) {$IP = getenv('HTTP_FORWARDED');}&lt;br /&gt;else {&lt;br /&gt;  $IP = $_SERVER['REMOTE_ADDR'];&lt;br /&gt;}&lt;br /&gt;return $IP;&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How does this get the actual IP?&lt;/b&gt;&lt;br /&gt;When servers send data to a client through a proxy, the protocol will still send the actual IP address through the environment variables in order for the proxy to be able to identify which client to send to.&lt;br /&gt;&lt;br /&gt;You should use this abreast (side by side) with $_SERVER['REMOTE_ADDR']. This function returns $_SERVER['REMOTE_ADDR'] if there's no secondary IP address.&lt;br /&gt;&lt;br /&gt;Pastebin: &lt;a href="http://thephpcode.pastebin.com/f24c2ec13"&gt;http://thephpcode.pastebin.com/f24c2ec13&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-7388908352526302657?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/7388908352526302657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=7388908352526302657' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7388908352526302657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7388908352526302657'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/01/php-getting-secondary-internet-protocol.html' title='PHP: Getting Secondary Internet Protocol (IP) Address'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6702293613971155067</id><published>2009-01-11T02:05:00.000Z</published><updated>2009-01-11T02:11:19.561Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='guide'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><title type='text'>MySQL: Grouping by most occurence in Column</title><content type='html'>I was developing a Content Management System (CMS) software when I encountered this issue of displaying most occurrence. So I managed to do this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;mysql&amp;gt; SELECT `DesireColumn`, COUNT(`DesireColumn`) AS `occurances` FROM `table` GROUP BY `DesireColumn` ORDER BY `occurances` DESC&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This query groups rows with same value in `DesireColumn`, then sorts the result by the number of occurances. It's useful to me, and I hope that it's useful to you too.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6702293613971155067?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6702293613971155067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6702293613971155067' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6702293613971155067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6702293613971155067'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/01/mysql-grouping-by-most-occurence-in.html' title='MySQL: Grouping by most occurence in Column'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-651247363319997695</id><published>2009-01-10T04:24:00.000Z</published><updated>2009-01-10T04:26:34.189Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='song'/><category scheme='http://www.blogger.com/atom/ns#' term='programmer'/><category scheme='http://www.blogger.com/atom/ns#' term='monkey'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Code Monkey - Jonathan Coulton</title><content type='html'>something out of programming for all programmers - Code Monkey by Jonathan Coulton.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.jonathancoulton.com/2006/04/14/thing-a-week-29-code-monkey/"&gt;http://www.jonathancoulton.com/2006/04/14/thing-a-week-29-code-monkey/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I think you can download the song straight from his blog. &lt;br /&gt;More about what is a code monkey: &lt;a href="http://en.wikipedia.org/wiki/Code_Monkey"&gt;http://en.wikipedia.org/wiki/Code_Monkey&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-651247363319997695?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/651247363319997695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=651247363319997695' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/651247363319997695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/651247363319997695'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/01/code-monkey-jonathan-coulton.html' title='Code Monkey - Jonathan Coulton'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6024561252117376022</id><published>2009-01-10T02:07:00.001Z</published><updated>2009-01-10T02:14:00.861Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='regex'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='PCRE'/><category scheme='http://www.blogger.com/atom/ns#' term='html'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='css'/><title type='text'>Cleaning/Stripping/Removing empty lines using PHP Regex (Regular Expressions)</title><content type='html'>Removing empty lines from whole chunk of HTML/CSS/Javascript output would do great effects. With the function below which uses preg_replace (Perl-Compatible Regular Expressions - PCRE Regex), you can easily strip off empty lines, which can improve your application's workload and speed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function removeEmptyLines($s)&lt;br /&gt;{&lt;br /&gt;return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $s);&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Use the function to clean buffers of HTML, CSS or Javascript before outputting to browsers/clients. It will do a great deal of magic.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6024561252117376022?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6024561252117376022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6024561252117376022' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6024561252117376022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6024561252117376022'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/01/cleaningstrippingremoving-empty-lines.html' title='Cleaning/Stripping/Removing empty lines using PHP Regex (Regular Expressions)'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-7442975986706774659</id><published>2009-01-04T03:37:00.001Z</published><updated>2009-11-17T23:16:01.791Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='header'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='exit'/><category scheme='http://www.blogger.com/atom/ns#' term='redirect'/><title type='text'>Why exit(); after Header redirect</title><content type='html'>You'll probably need a few HTTP 302 or 301 redirect in your PHP application when you develop it. To do a redirect, you can easily call:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;if(!$valid){&lt;br /&gt;  header($_SERVER['SERVER_PROTOCOL'].' 302 Found');&lt;br /&gt;  header('Location: nextpage.php');&lt;br /&gt;}&lt;br /&gt;unlink('tmp/2A4E22F1.dat');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;However, many people do not know that even after this header is called, the code after this line still executes! In the above code, the temporary file "2A4E22F1.dat" is still deleted. Therefore, you must add a exit(); after this redirect.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;if(!$valid){&lt;br /&gt;  header($_SERVER['SERVER_PROTOCOL'].' 302 Found');&lt;br /&gt;  header('Location: nextpage.php');&lt;br /&gt;  exit();&lt;br /&gt;}&lt;br /&gt;unlink('tmp/2A4E22F1.dat');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Since it is not valid and you did a redirect, the temporary file is not deleted. This is sometimes what developers miss out when doing redirects. hope it helps!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-7442975986706774659?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/7442975986706774659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=7442975986706774659' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7442975986706774659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7442975986706774659'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2009/01/why-exit-after-header-redirect.html' title='Why exit(); after Header redirect'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-8165209238995785627</id><published>2008-12-26T08:25:00.002Z</published><updated>2009-07-28T16:12:21.811+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='html'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Auto-Grow Textarea - doing it the easy way in Javascript</title><content type='html'>Just earlier on, I was working on a project for a friend of mine. The project was a php website that includes shopping cart, and some other modules. Well, lately i'm very into facebook and I was fascinated by their auto-growing text boxes. So i googled and found some javascript code snippets too. &lt;br /&gt;&lt;br /&gt;However, these scripts either require jQuery javascript framework or use time intervals (window.setInterval) to check for the height. These techniques made it look very ugly: and high resource usage too.&lt;br /&gt;&lt;br /&gt;Here, by combining String Object match method and textarea's onkeydown event, I can do it neatly in one line.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;textarea onkeypress="var m = this.value.match(/\n/g); if(m!=null) {this.rows = (m.length+1);}else{this.rows = 2;}"&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Upon each key press, the javascript code will check for the number of newline characters in the text area value. If there's no match, it will set to the default.&lt;br /&gt;&lt;br /&gt;See, it's better than installing jQuery framework just to do this auto-grow textarea! and you can do it selectively too!&lt;br /&gt;&lt;br /&gt;Edit:&lt;br /&gt;To apply this to all textarea DOM object, you can use jQuery to do so.&lt;br /&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;/*&amp;nbsp;&amp;lt;![CDATA[&amp;nbsp;*/ $(document).ready(function(){$("textarea").keypress(function(e){var m = this.value.match(/\n/g); if(m!=null) {this.rows = (m.length+1);}else{this.rows = 2;}});});/*&amp;nbsp;]]&amp;gt;&amp;nbsp;*/&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The code will work no matter where you place in the body, because the applying of keypress binding will only start when the whole document is loaded.  Hope the new code helps!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-8165209238995785627?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/8165209238995785627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=8165209238995785627' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8165209238995785627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/8165209238995785627'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/12/auto-grow-textarea-doing-it-easy-way-in.html' title='Auto-Grow Textarea - doing it the easy way in Javascript'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-1374142434899882075</id><published>2008-11-28T03:22:00.002Z</published><updated>2009-07-11T02:02:38.620+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='speed'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='pastebin'/><category scheme='http://www.blogger.com/atom/ns#' term='guide'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='Calculations'/><category scheme='http://www.blogger.com/atom/ns#' term='benchmark'/><title type='text'>PHP Loop Benchmarking - WHILE vs FOR</title><content type='html'>I was very bored today, when I suddenly realised that I should do some benchmarking for PHP myself. I created a script (can be found at thephpcode pastebin: &lt;a href="http://thephpcode.pastebin.com/f80e53fe"&gt;http://thephpcode.pastebin.com/f80e53fe&lt;/a&gt;) and run it on my xampp localhost.&lt;br /&gt;&lt;br /&gt;In the php benchmarking script, i am comparing 3 loops: FOR, WHILE and FOREACH. Amazingly, but not surprising, WHILE loop is the fastest compared to FOR and FOREACH, and as expected FOREACH is the slowest.&lt;br /&gt;&lt;br /&gt;This is my output:&lt;br /&gt;&lt;code&gt;0.000854015350342 seconds&lt;br /&gt;// for the FOR loop with 10000 times&lt;br /&gt;0.000696897506714 seconds&lt;br /&gt;// for the WHILE loop with 10000 times&lt;br /&gt;10000 elements&lt;br /&gt;// the number of elements in the array&lt;br /&gt;0.00111794471741 seconds&lt;br /&gt;// for the FOREACH loop with 10000 times&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I read about the WHILE loop on Javascript that WHILE is faster than FOR, but I didn't know that the same thing applies in PHP too. Well, here's a learning point for all of us.&lt;br /&gt;&lt;br /&gt;Note that the timings taken are an average of 5 runs spreaded across 5 mins (i.e. 1 run per minute) for the most accurate timings. Please note that the timings may differ from computer to computer. I am using Intel QuadCore 2.4GHz, 4GB RAM, Windows XP SP3, XAMPP 1.7.1, PHP 5.2.9.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-1374142434899882075?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/1374142434899882075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=1374142434899882075' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1374142434899882075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1374142434899882075'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/11/php-loop-benchmarking.html' title='PHP Loop Benchmarking - WHILE vs FOR'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-5275301007525705515</id><published>2008-11-23T10:50:00.000Z</published><updated>2009-01-11T02:04:52.519Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='Size'/><category scheme='http://www.blogger.com/atom/ns#' term='variable'/><category scheme='http://www.blogger.com/atom/ns#' term='browsers'/><category scheme='http://www.blogger.com/atom/ns#' term='bundle'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Multiple Pages with one PHP file</title><content type='html'>OMG.. i am so sorry for the delay. i was seriously slow and lazy as promised. well, today i am going to talk about having multiple pages with only one php files.&lt;br /&gt;&lt;br /&gt;many PHP noobs, they create one small module with tons and tons of pages. that's really bad because you duplicate loads and loads of the same thing! This is made possible using the system-defined variable $_GET, which returns all $_GET variable .. eg index.php?a=b to get the value 'b' you can use $_GET['a'].&lt;br /&gt;&lt;br /&gt;what you can do is to combine these pages into one php files. this makes things easy as you are able to backup less files: instead of hundreds of files.&lt;br /&gt;&lt;br /&gt;Previously you can have:&lt;br /&gt;+ index.php&lt;br /&gt;+ postback.php&lt;br /&gt;+ about.php&lt;br /&gt;+ process.php&lt;br /&gt;&lt;br /&gt;now you can have:&lt;br /&gt;+ index.php&lt;br /&gt;+ index.php?p=pb&lt;br /&gt;+ index.php?p=a&lt;br /&gt;+ index.php?p=prc&lt;br /&gt;&lt;br /&gt;Simply in &lt;span style="font-style:italic;"&gt;index.php&lt;/span&gt; you just have to use IF ELSE statements, or use any other conditional statements.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;index.php:&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;if($_GET['p']=='pb'){&lt;br /&gt;// display page for postback&lt;br /&gt;}elseif($_GET['p']=='a'){&lt;br /&gt;// for about page&lt;br /&gt;}elseif($_GET['p']=='prc'){&lt;br /&gt;// for processing&lt;br /&gt;}else{&lt;br /&gt;// displaying main page...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This is simple and easy. If you have common template for all the pages, you can combine and put them before or after the IF conditions. Most client browsers identify different GET headers as different pages, so it doesn't affect much of your application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-5275301007525705515?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/5275301007525705515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=5275301007525705515' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5275301007525705515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/5275301007525705515'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/11/multiple-pages-with-one-php-file.html' title='Multiple Pages with one PHP file'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-3601467587494181506</id><published>2008-10-15T13:00:00.000+01:00</published><updated>2008-12-26T09:03:44.029Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='break'/><category scheme='http://www.blogger.com/atom/ns#' term='programmer'/><title type='text'>Taking a Break...</title><content type='html'>Hello all php geeks C=&lt;br /&gt;&lt;br /&gt;i am taking a 4 week break, for my national exams are going on.&lt;br /&gt;During this period of time i won't be posting any updates on PHP.&lt;br /&gt;&lt;br /&gt;However, you still can comment on my blog or ask me questions on php.&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;while($thephpcode == true){&lt;br /&gt;   if($need_break){&lt;br /&gt;      break;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;Cheers&lt;br /&gt;Sam Yong&lt;br /&gt;thephpdeveloper&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-3601467587494181506?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/3601467587494181506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=3601467587494181506' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3601467587494181506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3601467587494181506'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/10/taking-break.html' title='Taking a Break...'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-37387169909296868</id><published>2008-09-17T14:28:00.000+01:00</published><updated>2008-09-17T14:46:17.464+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='variable'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='hacker'/><category scheme='http://www.blogger.com/atom/ns#' term='request'/><category scheme='http://www.blogger.com/atom/ns#' term='head'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='hijacker'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>$_REQUEST Security Problem</title><content type='html'>hello all! it has been quite some time. i have been studying for my national examinations. oh well, today i am going to talk about security issues in PHP regarding the $_REQUEST variable. &lt;br /&gt;&lt;br /&gt;The &lt;a href="http://sg2.php.net/manual/en/reserved.variables.request.php"&gt;$_REQUEST&lt;/a&gt; variable is a combination of key and values of &lt;a href="http://sg2.php.net/manual/en/reserved.variables.post.php"&gt;$_POST&lt;/a&gt;, &lt;a href="http://sg2.php.net/manual/en/reserved.variables.get.php"&gt;$_GET&lt;/a&gt; and &lt;a href="http://sg2.php.net/manual/en/reserved.variables.cookies.php"&gt;$_COOKIE&lt;/a&gt; variables. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script.&lt;br /&gt;&lt;br /&gt;The problem with this variable, is that when you are using it, you never know where the value came from. It might come from a cookie, it might come from a GET header request, or even a POST data. &lt;br /&gt;&lt;br /&gt;This often allows hijacking of sessions to occur. &lt;br /&gt;1) Hackers gets the Session ID of the user, visitor, or worse of all: Administrators.&lt;br /&gt;2) They inject into the cookies to get into the session of the user/administrator. &lt;br /&gt;3) this allows the server to show the hijacker what the real user sees.&lt;br /&gt;4) and the hijacker is also able to access whatever the user is able to access.&lt;br /&gt;&lt;br /&gt;Worse still, if you want to double check the session via a POST and GET, and you use the $_REQUEST variable to check, the hacker can simply put it into cookie and he passes through.&lt;br /&gt;&lt;br /&gt;It also allows bots to POST data easily using cookies if you use $_REQUEST. Especially if you have forms using $_REQUEST, the bot can keep bypassing your form using cookies or get headers.&lt;br /&gt;&lt;br /&gt;You should use a more specific variable to further secure your application. Well, that's all i have. Goodnights!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-37387169909296868?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/37387169909296868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=37387169909296868' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/37387169909296868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/37387169909296868'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/09/request-security-problem.html' title='$_REQUEST Security Problem'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-4747820369467628686</id><published>2008-09-10T11:54:00.000+01:00</published><updated>2008-09-10T12:09:35.215+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='Directory'/><category scheme='http://www.blogger.com/atom/ns#' term='variable'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><category scheme='http://www.blogger.com/atom/ns#' term='bundle'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Script Bundle</title><content type='html'>I have recently started building a php scripts bundle for sales. The bundle includes&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Password and String Encryption Class - pcrypt&lt;br/&gt;A class that helps you to encode a string with a password and a random salt. The same password is required to decode the encrypted string. useful for storing data that requires password encryption. it offers common hashing methods: SHA1, MD5 and CRC32.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Hypertext Markup Language PHP Builder Class - htmlbuilder&lt;br/&gt;Using this class, you can build XHTML and HTML valid web pages with php codes. it uses object-based codes and you can nest objects in objects with class parent-children relations.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Javascript in HTML Optimizer Control Class - scriptcontrol&lt;br/&gt;Puts all the codes in javascripts tags into a file and call from there. this allow optimized loading and thus decreasing server load.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Script and File Pre-Processor - sp&lt;br/&gt;Pre-process your xml, javascript and css files with this processor. it is not a class, instead, you can call it directly. Also, instead of calling individual files, you can combine many files into one: eg sp.php?f=file1.css;file2.css;file4.css&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Alternative Logging - altlog&lt;br/&gt;a great logging tool that allows error logging to be managed easy via a class. commonly used by the rest of the scripts for error logging.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;PHP Cache Control - cachec&lt;br/&gt;Allows you to cache variables, data so as to speed up page loading. it saves cache into files in a directory and will load it later for faster loading.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Would you want to buy it? Comment your thoughts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-4747820369467628686?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/4747820369467628686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=4747820369467628686' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4747820369467628686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4747820369467628686'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/09/script-bundle.html' title='Script Bundle'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6404781985752352438</id><published>2008-08-30T14:49:00.000+01:00</published><updated>2008-08-30T14:59:26.624+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='integration'/><category scheme='http://www.blogger.com/atom/ns#' term='pastebin'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Pastebin Integration</title><content type='html'>Hello all!&lt;br /&gt;&lt;br /&gt;i am proud to announce that in future, a copy of code examples will also be on &lt;a href="http://thephpcode.pastebin.com/"&gt;Pastebin&lt;/a&gt; at &lt;a href="http://thephpcode.pastebin.com/"&gt;http://thephpcode.pastebin.com/&lt;/a&gt;. This will allow all to post your source codes up there and discuss it here on thephpcode.blogspot.com.&lt;br /&gt;&lt;br /&gt;This also means that, you can see the codes clearly and find help directly when you click from the functions in the source code. and with the added usefulness of line numbers, you can look at the code clearly.&lt;br /&gt;&lt;br /&gt;hope it helps all.&lt;br /&gt;&lt;br /&gt;cheers&lt;br /&gt;sam&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6404781985752352438?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6404781985752352438/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6404781985752352438' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6404781985752352438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6404781985752352438'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/08/pastebin-integration.html' title='Pastebin Integration'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-3554804720191595253</id><published>2008-08-12T13:36:00.001+01:00</published><updated>2009-08-16T12:46:11.704+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='Directory'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='filename'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Getting a recursive file list in PHP: Code Example</title><content type='html'>Ever wonder how you can get an array of files in a directory. ALL the files, including those in the subfolders? Sure you can do that! an example is shown below! The function below returns an array tree of files. It recursively get files in a folder, then calls itself again for all the sub folders.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function dirfiles($dirname = '.', $relative = false) {&lt;br /&gt;if($dirname == ''){$dirname = '.';}&lt;br /&gt;if (!is_dir($dirname) || !is_readable($dirname)) {&lt;br /&gt;// check whether the directory is valid.&lt;br /&gt;return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$a = array();&lt;br /&gt;&lt;br /&gt;$handle = opendir($dirname);&lt;br /&gt;while (false !== ($file = readdir($handle))) {&lt;br /&gt;if ($file != '.' &amp;&amp; $file != '..' &amp;&amp; is_readable($dirname . DIRECTORY_SEPARATOR . $file)) {&lt;br /&gt;if (is_dir($dirname . DIRECTORY_SEPARATOR . $file)) {&lt;br /&gt;$a[($relative ? $file : $dirname . DIRECTORY_SEPARATOR . $file)] = dirfiles($dirname . DIRECTORY_SEPARATOR . $file, $relative);&lt;br /&gt;}else{&lt;br /&gt;$a[] = ($relative ? $file : $dirname . DIRECTORY_SEPARATOR . $file);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;closedir($handle);&lt;br /&gt;&lt;br /&gt;return $a;&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can specify whether to return each array in an relative manner or not. &lt;br /&gt;&lt;br /&gt;$relative = true: &lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [data] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [0] =&gt; dataone.inc.php&lt;br /&gt;            [1] =&gt; user.inc.php&lt;br /&gt;            [2] =&gt; forum.inc.php&lt;br /&gt;        )&lt;br /&gt;&lt;br /&gt;    [0] =&gt; constants.inc.php&lt;br /&gt;    [1] =&gt; functions.inc.php&lt;br /&gt;    [2] =&gt; header.inc.php&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$relative = false:&lt;br /&gt;&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [dat/inc/data] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [0] =&gt; dat/inc/datadataone.inc.php&lt;br /&gt;            [1] =&gt; dat/inc/datauser.inc.php&lt;br /&gt;            [2] =&gt; dat/inc/dataforum.inc.php&lt;br /&gt;        )&lt;br /&gt;&lt;br /&gt;    [0] =&gt; dat/inc/constants.inc.php&lt;br /&gt;    [1] =&gt; dat/inc/functions.inc.php&lt;br /&gt;    [2] =&gt; dat/inc/header.inc.php&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;For ($relative = true), the presentation would be nicer, however in ($relative = false), the array would be more useful for argument of another file access function.&lt;br /&gt;&lt;br /&gt;hope it is useful ^^&lt;br /&gt;&lt;br /&gt;Link to code example on &lt;a href="http://pastebin.com/"&gt;pastebin&lt;/a&gt;: &lt;a href="http://thephpcode.pastebin.com/f495b59a1"&gt;http://thephpcode.pastebin.com/f495b59a1&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-3554804720191595253?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/3554804720191595253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=3554804720191595253' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3554804720191595253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/3554804720191595253'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/08/getting-recursive-file-list-in-php-code.html' title='Getting a recursive file list in PHP: Code Example'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-939093333857012118</id><published>2008-08-03T23:18:00.000+01:00</published><updated>2008-08-03T23:34:50.193+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><category scheme='http://www.blogger.com/atom/ns#' term='json'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><title type='text'>Why JSON over XML in AJAX?</title><content type='html'>Many web applications nowadays use AJAX to help them in decreasing server load and of course speed up the website. AJAX have been part of the web 2.0 technologies and is used widely in many websites. &lt;br /&gt;&lt;br /&gt;AJAX have this idea of calling back the server from the client side to accomplish some task, such as posting back data to the server or getting new information from the server. it can been seen as form submitter, tips of the day ticker, tabbed boxes and more.&lt;br /&gt;&lt;br /&gt;However, developers have the choice of language of the message that is responded from the server after the postback or request have been made by AJAX from client side. It can either be in the form of &lt;a href="http://www.json.org/"&gt;Javascript Object Notation (JSON)&lt;/a&gt; or &lt;a href="http://www.w3.org/XML/"&gt;Extensible Markup Language (XML)&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;JSON generally have advantages over XML - firstly because JSON is much lightweight compared to XML. As JSON only contains one character notations, it saves more bandwidth and load time compared to XML which uses tags.&lt;br /&gt;&lt;br /&gt;Secondly, the multiple-dimension JSON is also attractive to developers, as JSON's parsing on PHP is easy, with only 2 functions, whereas XML uses multiple functions to parse - which may be confusing.&lt;br /&gt;&lt;br /&gt;Thirdly, JSON is directly readable on client side using Javascript, thus you save time parsing it on server AND client side. For XML, you will need to parse the data again in order to use it.&lt;br /&gt;&lt;br /&gt;To use JSON directly in Javascript: &lt;code&gt;var myObject = eval('(' + myJSONtext + ')');&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For course, the X in AJAX originally refers to XML - asynchronous JavaScript and XML - but as time goes by, developers will find satisfying format for their needs of communication between server and client. Even in &lt;a href="http://www.asp.net/"&gt;ASP.net&lt;/a&gt;, AJAX messages in Updatepanels and other controls are split using "|".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-939093333857012118?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/939093333857012118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=939093333857012118' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/939093333857012118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/939093333857012118'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/08/why-json-over-xml-in-ajax.html' title='Why JSON over XML in AJAX?'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6146787684930658065</id><published>2008-07-31T14:51:00.000+01:00</published><updated>2008-07-31T14:57:36.853+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='class'/><category scheme='http://www.blogger.com/atom/ns#' term='tips'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='instance'/><title type='text'>Setting read-only variables of PHP classes</title><content type='html'>Many would ask, how can I make variables of PHP classes read only? There's nothing similar to other programming languages such as C# to use the readonly keyword.&lt;br /&gt;&lt;br /&gt;Oh well, there is a work around instead. For example, in the class &lt;code&gt;pClass&lt;/code&gt;, there is this variable named &lt;code&gt;$read&lt;/code&gt; i want to make read-only. So i will have to do this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;class pClass{&lt;br /&gt;&lt;br /&gt;private $read = '';&lt;br /&gt;&lt;br /&gt;public function __get($name){ // this will be called when a variable is read.&lt;br /&gt;return $this-&gt;$name; // returns the variable&lt;br /&gt;// without this function, PHP will return an error.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note that by setting this function, all private variables in your class are readable. However, you still can filter them in the &lt;code&gt;__get&lt;/code&gt; function before returning the result..&lt;br /&gt;&lt;br /&gt;Note that the function have 2 underscores, not one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6146787684930658065?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6146787684930658065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6146787684930658065' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6146787684930658065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6146787684930658065'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/07/setting-read-only-variables-of-php.html' title='Setting read-only variables of PHP classes'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-951468341771599299</id><published>2008-07-31T14:43:00.000+01:00</published><updated>2008-08-03T23:38:04.372+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='array'/><category scheme='http://www.blogger.com/atom/ns#' term='class'/><category scheme='http://www.blogger.com/atom/ns#' term='add'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='instance'/><category scheme='http://www.blogger.com/atom/ns#' term='functions'/><title type='text'>Adding class instances to Array()</title><content type='html'>I was coding a script halfway, when i ran into this case that i had never encounter before: adding class instances into arrays. I asked myself, was that possible? Well, the answer will reveal below.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;class pClass{&lt;br /&gt;&lt;br /&gt;public $_array = array();&lt;br /&gt;&lt;br /&gt;public function display(){&lt;br /&gt;     print_r($this-&gt;_array);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$p = new pClass();&lt;br /&gt;$second = new pClass();&lt;br /&gt;$p-&gt;_array[] = $second;&lt;br /&gt;// IT IS POSSIBLE! xD&lt;br /&gt;$p-&gt;display(); // outputs: Array ( [0] =&gt; pClass Object ( [_array] =&gt; Array ( ) ) ) &lt;br /&gt;// how cool.&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Fortunately,  i tested and it works. I added a class instance to the array of another class. On top of that, the both can be instances of the same class. Well, this allows parent-children relationships of classes.&lt;br /&gt;&lt;br /&gt;In addition, this will allow recursive addition of class, since it is a class in a class. Well, why not?&lt;br /&gt;&lt;br /&gt;Adding class instances to array would mean that multiple instances can also be added to one class, via this method too!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-951468341771599299?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/951468341771599299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=951468341771599299' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/951468341771599299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/951468341771599299'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/07/adding-class-instances-to-array.html' title='Adding class instances to Array()'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-7741405309948800126</id><published>2008-07-20T16:39:00.000+01:00</published><updated>2008-07-20T17:10:53.294+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='projects'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='facebook'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='programmer'/><category scheme='http://www.blogger.com/atom/ns#' term='applications'/><title type='text'>MySQL Query from PHP</title><content type='html'>i was coordinating with my external project's &lt;a href="http://www.facebook.com/"&gt;Facebook&lt;/a&gt; App programmer, when i realised that i haven't write an article on how to query using &lt;a href="http://www.mysql.com/"&gt;MySQL&lt;/a&gt; from &lt;a href="http://www.php.net/"&gt;PHP&lt;/a&gt;. it's simple. so let's get the steps right.&lt;br /&gt;&lt;br /&gt;First of all, you will need to connect to your MySQL server first before you can query. this is to verify that the user you are querying with have authorisation to access certain features of MySQL, such as limited table/database privileges.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$link = @mysql_connect(%server%,%user%,%password%);&lt;/code&gt;&lt;br /&gt;- &lt;code&gt;$link&lt;/code&gt; contains the information of the connection that you have made and might be required by other mysql_* functions. it becomes false when the mysql_connect returns error as false.&lt;br /&gt;- &lt;code&gt;%server%&lt;/code&gt; is the server address, and most probably local MySQL server should be "localhost"&lt;br /&gt;- &lt;code&gt;%user%&lt;/code&gt; is the user name of the account used to access MySQL on %server%&lt;br /&gt;- &lt;code&gt;%password%&lt;/code&gt; confirms the identity.&lt;br /&gt;&lt;br /&gt;Only when connected, MySQL then can be accessed using the other functions, such as &lt;code&gt;mysql_select_db()&lt;/code&gt;, &lt;code&gt;mysql_query()&lt;/code&gt;, &lt;code&gt;mysql_fetch_array()&lt;/code&gt;. Now, you will need to select a specific database to work in. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;$return = @mysql_select_db(%database%);&lt;/code&gt;&lt;br /&gt;- &lt;code&gt;$return&lt;/code&gt; returns the value true or false. False on failure.&lt;br /&gt;- &lt;code&gt;%database%&lt;/code&gt; is the name of the database without ` warp.&lt;br /&gt;&lt;br /&gt;If both functions are a success, then you are able to use mysql_query() to query and get results from the database specified in mysql_select_db().&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$result = @mysql_query(%query%);&lt;/code&gt;&lt;br /&gt;- &lt;code&gt;$result&lt;/code&gt; is the data that is returned from &lt;code&gt;%query%&lt;/code&gt; [WARNING: $result is not an array, it just contains data for other functions to process]. it returns false on error.&lt;br /&gt;- &lt;code&gt;%query%&lt;/code&gt; is the fully query string. See MySQL query syntax at &lt;a href="http://dev.mysql.com/doc/"&gt;http://dev.mysql.com/doc/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Since the &lt;code&gt;$result&lt;/code&gt; of the mysql_query function is not an array or object, or anything that PHP can read properly into variables, you will need to use functions like &lt;code&gt;mysql_fetch_array()&lt;/code&gt; or &lt;code&gt;mysql_ fetch_ assoc()&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;To read off all the rows of the result, do a while loop.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;$table = array();&lt;br /&gt;while($array = @mysql_fetch_array($result)){&lt;br /&gt;$table[] = $array;&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;when &lt;code&gt;mysql_fetch_array()&lt;/code&gt; reaches no more result, it will return a false, and thus breaking the loop. &lt;code&gt;$table&lt;/code&gt; will be an array of rows of the result returned, where &lt;code&gt;$result&lt;/code&gt; is the variable returned by &lt;code&gt;mysql_query()&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;After you have gotten the results in an array, you can free the &lt;code&gt;$result&lt;/code&gt; variable as it might occupy the system memory. To free the result, use &lt;code&gt;mysql_free_result()&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;@mysql_free_result($result);&lt;/code&gt;&lt;br /&gt;- &lt;code&gt;$result&lt;/code&gt; is the variable that is returned by mysql_query. function does nothing if variable is false.&lt;br /&gt;&lt;br /&gt;When you are done with everything on MySQL, you can use &lt;code&gt;mysql_close()&lt;/code&gt; to close the connection. Connection is automatically closed when the script terminates.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;@mysql_close([$link]);&lt;/code&gt;&lt;br /&gt;- where $link is the connection information returned by &lt;code&gt;mysql_connect()&lt;/code&gt;. function closes last opened connection if $link is not specified.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-7741405309948800126?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/7741405309948800126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=7741405309948800126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7741405309948800126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/7741405309948800126'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/07/mysql-query-from-php.html' title='MySQL Query from PHP'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6710779458308295267</id><published>2008-06-28T03:08:00.001+01:00</published><updated>2008-06-28T03:20:05.008+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='notes'/><category scheme='http://www.blogger.com/atom/ns#' term='localhost'/><category scheme='http://www.blogger.com/atom/ns#' term='domain name'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='functions'/><title type='text'>PHP Session functions and notes</title><content type='html'>like any other web server-side scripts, PHP has its &lt;a href="http://www.php.net/manual/en/book.session.php"&gt;Session&lt;/a&gt; functions and methods. Every time a user opens your website, you consider it a session and when the user is inactive for sometime, the session is gone. &lt;br /&gt;&lt;br /&gt;Also, when you want to pass parameters from one page to another, you might notice normal variables will not stay when loaded another page. However, you can declare (array)$_SESSION variables to keep the variables in the session and you can use it on any other page.&lt;br /&gt;&lt;br /&gt;The only condition is that, you must start the session using function &lt;span style="font-weight:bold;"&gt;void session_start(void)&lt;/span&gt; at the start of PHP scripts that you want to use Session.&lt;br /&gt;&lt;br /&gt;When your domain (eg http://www.johnsmith.com/) uses subdomain (eg http://sub.johnsmith.com/), using the normal session_start() is not enough. The session from your domain will be different from your sub domain.&lt;br /&gt;&lt;br /&gt;So, you can add the following in front of session_start() to configure this: session_set_cookie_params(t, '/',dn,false,true); - where t represents the timeout before the session expires, '/' represents that the session can be used from the whole domain, and dn should be a .&amp;lt;yourdomainname&amp;gt;.com where you add a . in front of your domain name without the "www"&lt;br /&gt;&lt;br /&gt;Also, during my own testing experience, i noticed that if you put localhost in the "dn", the session will not work on any browsers and PHP will keep renewing the session, which may result in undesirable returns.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6710779458308295267?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6710779458308295267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6710779458308295267' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6710779458308295267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6710779458308295267'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/06/php-session-functions-and-notes.html' title='PHP Session functions and notes'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-6757864272940362885</id><published>2008-06-17T15:33:00.000+01:00</published><updated>2008-06-17T15:53:44.052+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='include'/><category scheme='http://www.blogger.com/atom/ns#' term='head'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='asp'/><title type='text'>PHP script include() function</title><content type='html'>One of the things I regard best as a developer, is the &lt;a href="http://www.php.net/include"&gt;include() function&lt;/a&gt; of PHP.&lt;br /&gt;&lt;br /&gt;include() is something like the MasterPages and ContentPages in ASP.NET. You can use it for defining site-wide variables and constants, defining functions and classes, or even  putting site-wide processes and functions into it and call it from anywhere else.&lt;br /&gt;&lt;br /&gt;For example, i need to display "hello world" on both "&lt;span style="font-weight:bold;"&gt;a.php&lt;/span&gt;" and "&lt;span style="font-weight:bold;"&gt;b.php&lt;/span&gt;" pages. I can use the include() function to do this.  first, i put&lt;br /&gt;&lt;span style="font-style:italic;"&gt;&amp;lt;?php echo "hello world"; ?&amp;gt;&lt;/span&gt;&lt;br /&gt;into "&lt;span style="font-weight:bold;"&gt;head.php&lt;/span&gt;", then i put&lt;br /&gt;&lt;span style="font-style:italic;"&gt;&amp;lt;?php include('head.php'); ?&amp;gt;&lt;/span&gt;&lt;br /&gt;into both pages "&lt;span style="font-weight:bold;"&gt;a.php&lt;/span&gt;" and "&lt;span style="font-weight:bold;"&gt;b.php&lt;/span&gt;". Then, both pages "&lt;span style="font-weight:bold;"&gt;a.php&lt;/span&gt;" and "&lt;span style="font-weight:bold;"&gt;b.php&lt;/span&gt;" will show up "hello world".&lt;br /&gt;&lt;br /&gt;both pages will run "&lt;span style="font-weight:bold;"&gt;head.php&lt;/span&gt;" at the line where include() function is. However, there are some unexpected results of using include().&lt;br /&gt;&lt;br /&gt;For example, i put "&lt;span style="font-weight:bold;"&gt;head.php&lt;/span&gt;" into a folder call "&lt;span style="font-weight:bold;"&gt;folder&lt;/span&gt;", and i have this script "&lt;span style="font-weight:bold;"&gt;call.php&lt;/span&gt;" which have the following&lt;br /&gt;&lt;span style="font-style:italic;"&gt;&amp;lt;?php include('folder/head.php'); ?&amp;gt;&lt;/span&gt;&lt;br /&gt;The current directory for "&lt;span style="font-weight:bold;"&gt;head.php&lt;/span&gt;" is no longer &lt;span style="font-style:italic;"&gt;'folder/'&lt;/span&gt;, but it is now &lt;span style="font-style:italic;"&gt;'/'&lt;/span&gt;, since it is called by "&lt;span style="font-weight:bold;"&gt;call.php&lt;/span&gt;". Included scripts will always use the current directory of the parent script. (See more: &lt;a href="http://sg.php.net/manual/en/ref.dir.php"&gt;Directory Functions&lt;/a&gt; and &lt;a href="http://www.php.net/chdir"&gt;chdir() function&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://www.php.net/return"&gt;return statement&lt;/a&gt; can be used in the main scope of included scripts to return the control back to the parent script immediately. example:&lt;br /&gt;&lt;span style="font-style:italic;"&gt;&amp;lt;?php return; $I++; ?&amp;gt;&lt;/span&gt;&lt;br /&gt;variable $I will not be incremented. but if you run this code as parent main scope, return will not work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-6757864272940362885?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/6757864272940362885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=6757864272940362885' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6757864272940362885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/6757864272940362885'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/06/php-script-include-function.html' title='PHP script include() function'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-1971430743151713742</id><published>2008-06-04T23:10:00.001+01:00</published><updated>2009-07-07T16:00:06.522+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='upgrade'/><category scheme='http://www.blogger.com/atom/ns#' term='apache friends'/><category scheme='http://www.blogger.com/atom/ns#' term='guide'/><category scheme='http://www.blogger.com/atom/ns#' term='xampp'/><title type='text'>Upgrading MySQL - with xampp installed first</title><content type='html'>Hello all!&lt;br /&gt;&lt;br /&gt;We have noted that the internet requires an article on how to upgrade your MySQL server with xampp installed first. MySQL server on your computer are be shared among many HTTP servers - Apache or IIS - on the same operating system. Thus, there are possibilities you might want to upgrade or downgrade your MySQL server.&lt;br /&gt;&lt;br /&gt;xampp by Apache Friends is a package that includes the Apache server, PHP and MySQL together with many other wonderful functions for local web development(localhost). However, the MySQL server included is never up to date. So below is how you upgrade your MySQL server.&lt;br /&gt;&lt;br /&gt;1) Download MySQL server from &lt;a href="http://dev.mysql.com/downloads/"&gt;http://dev.mysql.com/downloads/&lt;/a&gt;&lt;br /&gt;2) When you set up MySQL server, one of the steps of the installer should show an "Advanced" button, click on it.&lt;br /&gt;3) Following you should see where the server is about to install to. Change it to %your_xampp_installation_path%\mysql\ (e.g. C:\xampp\mysql\)&lt;br /&gt;4) After installation, your MySQL is upgraded.&lt;br /&gt;&lt;br /&gt;Note that if you do not change the installation directory of MySQL server, the server will not be upgraded as the default server is still in your xampp folder. After upgrading, you can use MySQL Administrator (GUI Tools) or MyPHPAdmin to check the server version.&lt;br /&gt;&lt;br /&gt;Note that you are advised to back up your database information before performing such upgrade or maintenance work. I will not be held responsible for any problems caused directly or indirectly by my articles or whatsoever.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-1971430743151713742?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/1971430743151713742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=1971430743151713742' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1971430743151713742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/1971430743151713742'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/06/upgrading-mysql-with-xampp-installed.html' title='Upgrading MySQL - with xampp installed first'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-763135055269200366</id><published>2008-06-04T13:17:00.000+01:00</published><updated>2008-08-30T14:46:12.349+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='example'/><category scheme='http://www.blogger.com/atom/ns#' term='Size'/><category scheme='http://www.blogger.com/atom/ns#' term='Directory'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Calculations'/><title type='text'>Directory Size Calculations with Code Examples</title><content type='html'>Calculating files are easy. Using the php filesize() function, you can easily find out the file size. However, have you encountered a case whereby you need to calculate the whole directory, including sub folders and the files in them?&lt;br /&gt;&lt;br /&gt;In this article, we are going to talk about how to recursively calculate the total folder size of a directory. You can add thousands of folders and millions of files into a single folder, and this customized php function is able to calculate out the size of the directory. You can also use it for calculating your disk space too!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;function dirsize($dirname) {&lt;br /&gt;    if (!is_dir($dirname) || !is_readable($dirname)) {&lt;br /&gt;        // check whether the directory is valid.&lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    $dirname_stack[] = $dirname;&lt;br /&gt;    $size = 0;&lt;br /&gt;&lt;br /&gt;    do {&lt;br /&gt;        $dirname = array_shift($dirname_stack);&lt;br /&gt;        $handle = opendir($dirname);&lt;br /&gt;        while (false !== ($file = readdir($handle))) {&lt;br /&gt;            if ($file != '.' &amp;&amp; $file != '..' &amp;&amp; is_readable($dirname . DIRECTORY_SEPARATOR . $file)) {&lt;br /&gt;                if (is_dir($dirname . DIRECTORY_SEPARATOR . $file)) {&lt;br /&gt;                    $dirname_stack[] = $dirname . DIRECTORY_SEPARATOR . $file;&lt;br /&gt;                }&lt;br /&gt;                $size += filesize($dirname . DIRECTORY_SEPARATOR . $file);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        closedir($handle);&lt;br /&gt;    } while (count($dirname_stack) &gt; 0);&lt;br /&gt;&lt;br /&gt;    return $size;&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope this helps you in building it in as a useful function in your administration panel of your website.&lt;br /&gt;&lt;br /&gt;Link to code example on &lt;a href="http://pastebin.com/"&gt;pastebin&lt;/a&gt;: &lt;a href="http://thephpcode.pastebin.com/f24c2ec13"&gt;http://thephpcode.pastebin.com/f24c2ec13&lt;/a&gt;&lt;br /&gt;http://thephpcode.pastebin.com/f24c2ec13&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-763135055269200366?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/763135055269200366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=763135055269200366' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/763135055269200366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/763135055269200366'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/06/directory-size-calculations-with-code.html' title='Directory Size Calculations with Code Examples'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-2114289937615020742</id><published>2008-05-23T11:11:00.000+01:00</published><updated>2008-05-23T11:34:12.652+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IDE'/><category scheme='http://www.blogger.com/atom/ns#' term='guide'/><title type='text'>PHP IDE choosing guide</title><content type='html'>There are plenty of Integrated Development Environment (IDE) - softwares or hardwares that form up the environment for the development of softwares or other hardwares - created for the programming of PHP codes. &lt;br /&gt;&lt;br /&gt;Some of them include &lt;a href="http://devphp.sourceforge.net/"&gt;Dev-PHP&lt;/a&gt;, &lt;a href="http://www.aptana.com/"&gt;Aptana Studio&lt;/a&gt;, &lt;a href="http://www.adobe.com/products/dreamweaver/"&gt;Adobe Dreamweaver&lt;/a&gt; and more.. But what is the best for you, since PHP is such a dynamic and complex language?&lt;br /&gt;&lt;br /&gt;There are a few pointers you should consider before using that IDE of your choice.&lt;br /&gt;1) Patches and security fixes to the software - are they kept up to date with the latest version of PHP?&lt;br /&gt;2) Does it allow you to integrate PHP with other platforms such as AJAX and XML?&lt;br /&gt;3) Are the code correctly colored?&lt;br /&gt;4) Are the tools available with the packages useful?&lt;br /&gt;5) Are the tools available easy to use?&lt;br /&gt;6) Is it free for use/production?&lt;br /&gt;&lt;br /&gt;Those pointers are just some guide to choosing your default IDE. Of course, you can combine them and use multiple IDE on one single project. It's good that you experiment out the available IDEs and find the one that suits you best.&lt;br /&gt;&lt;br /&gt;Cheers&lt;br /&gt;Sam Yong&lt;br /&gt;&lt;br /&gt;NEXT UP: &lt;b&gt;Directory Size Calculations&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-2114289937615020742?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/2114289937615020742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=2114289937615020742' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2114289937615020742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/2114289937615020742'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/05/php-ide-choosing-guide.html' title='PHP IDE choosing guide'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-9025903115893158701</id><published>2008-05-09T04:52:00.000+01:00</published><updated>2008-05-09T05:09:32.608+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='apache friends'/><category scheme='http://www.blogger.com/atom/ns#' term='xampp'/><title type='text'>Setting up XAMPP - local php environment</title><content type='html'>Hello to all!&lt;br /&gt;&lt;br /&gt;Today we are going to talk about how to set up a local PHP testing environment on your own computer using the server localhost or 127.0.0.1. It is understood that PHP is installed on a server in order to parse PHP files and output into the browser, but how are you going to do that on your own computer where you have so many things running about?&lt;br /&gt;&lt;br /&gt;Well, we'll use &lt;a href="http://www.apachefriends.org/en/xampp.html"&gt;xampp&lt;/a&gt;, by &lt;a href="http://www.apachefriends.org/en/index.html"&gt;Apache Friends&lt;/a&gt;, which is an apache package with &lt;a href="http://www.mysql.com/"&gt;MySQL community version&lt;/a&gt;, &lt;a href="http://www.php.net/"&gt;PHP&lt;/a&gt;, FTP support, and more. It supports many platforms: Windows, Mac, Linux, Solaris and more!&lt;br /&gt;&lt;br /&gt;What's more? xampp is free!&lt;br /&gt;&lt;br /&gt;Installing xampp will take awhile after you have selected the appropriate download for your platform. After installing, you will be able to access the server using &lt;a href="http://localhost/"&gt;http://localhost/&lt;/a&gt;, or add the port number if you use it, on your browser.&lt;br /&gt;&lt;br /&gt;You will need to remember that other people that can connect to you can access your apache server using your IP address. You will need to set some of the security options available on the server mainpage.&lt;br /&gt;&lt;br /&gt;To edit the files on the server, either you can use the ftp protocol, or you can access it via your local hard drive (for example on Windows, htdocs folder inside where xampp is installed).&lt;br /&gt;&lt;br /&gt;And if you want to upgrade &lt;a href="http://www.mysql.com/"&gt;MySQL&lt;/a&gt;, just the version of MySQL from the &lt;a href="http://www.mysql.com/"&gt;official website&lt;/a&gt;, and install into where xampp is installed.&lt;br /&gt;&lt;br /&gt;Well, signing off. &lt;br /&gt;Sam Yong&lt;br /&gt;&lt;br /&gt;NEXT UP: &lt;span style="font-weight:bold;"&gt;PHP IDE choosing guide&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-9025903115893158701?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/9025903115893158701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=9025903115893158701' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9025903115893158701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/9025903115893158701'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/05/setting-up-xampp-local-php-environment.html' title='Setting up XAMPP - local php environment'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3772193622268326056.post-4485972564465725293</id><published>2008-05-06T09:42:00.000+01:00</published><updated>2008-05-23T11:32:42.727+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='introduction'/><title type='text'>thephpcode - opening</title><content type='html'>hello all.&lt;br /&gt;&lt;br /&gt;i am sam yong, &lt;a href="http://thephpdeveloper.blogspot.com/"&gt;thephpdeveloper blogger&lt;/a&gt;, and i am 15 this year, yes going 16. i currently live in singapore, and i have 2 years, maybe a little more, of PHP and programming logic experience. I have opened and work in quite a number of companies, but now i am here to share my experience with you.&lt;br /&gt;&lt;br /&gt;here in this blog, i am sharing php codes and functions together with its explanations. you might find them useful, find bugs in them or you might just love the way i do the codes. but i am willing to learn PHP with you.&lt;br /&gt;&lt;br /&gt;if you are a beginner in PHP, i suggest that you read my next post, on how to set up a PHP server environment on your own computer and you can learn PHP without the use of purchased servers.&lt;br /&gt;&lt;br /&gt;also, i hand-code all my codes, and they are not going to be formatted. you can format them in your own IDE (Integrated Development Environment) so that you can read them.&lt;br /&gt;&lt;br /&gt;Cheers&lt;br /&gt;Sam Yong&lt;br /&gt;&lt;br /&gt;NEXT UP: &lt;span style="font-weight:bold;"&gt;Setting up XAMPP - local php environment&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3772193622268326056-4485972564465725293?l=thephpcode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thephpcode.blogspot.com/feeds/4485972564465725293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3772193622268326056&amp;postID=4485972564465725293' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4485972564465725293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3772193622268326056/posts/default/4485972564465725293'/><link rel='alternate' type='text/html' href='http://thephpcode.blogspot.com/2008/05/thephpcode-opening.html' title='thephpcode - opening'/><author><name>thephpdeveloper</name><uri>http://www.blogger.com/profile/14054652790388018898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_MNIqNKv86k4/SlIb3Zg9qaI/AAAAAAAAAMo/WPNGoOmUO3s/S220/n649546428_3024.jpg'/></author><thr:total>2</thr:total></entry></feed>
