<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP, CSS, HTML, Web &#38; beyond &#187; PHP</title>
	<atom:link href="http://www.joseairosa.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joseairosa.com</link>
	<description>Programming Tips &#38; Tricks</description>
	<lastBuildDate>Mon, 23 Jan 2012 12:46:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>PHP Cropimage Script (memcache and APC support)</title>
		<link>http://www.joseairosa.com/2011/08/03/php-cropimage-script-memcache-and-apc-support/</link>
		<comments>http://www.joseairosa.com/2011/08/03/php-cropimage-script-memcache-and-apc-support/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 21:35:24 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[cropping]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[rewrite rules]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[website optimization]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=305</guid>
		<description><![CDATA[Hello! &#160; This script will enable you to automaticaly resize images without loosing quality. It uses a simple math formulas to calculate the desired final size and then rerenders the image. The usage is very simples. On you HTML code just create an image and replace the src with: cropimage.php?src=img/myimage.jpg&#38;size=320&#215;240 src &#8211; the source of [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>&nbsp;</p>
<p>This script will enable you to automaticaly resize images without loosing quality.<br />
It uses a simple math formulas to calculate the desired final size and then rerenders the image.</p>
<p>The usage is very simples. On you HTML code just create an image and replace the src with:</p>
<p>cropimage.php?src=img/myimage.jpg&amp;size=320&#215;240</p>
<p>src &#8211; the source of the image itself<br />
size &#8211; the size that the image should have. If the size is not directly compatible with the original size it will display a simple background and the image with the correct size on top.</p>
<p><em>Example: cropimage.php?src=img/myimage.jpg&amp;size=320&#215;240</em></p>
<p>If it&#8217;s a square image you can just use <strong>myimage.jpg&amp;size=320</strong> and it will make a 320&#215;320 image.</p>
<p>If you don&#8217;t want that nasty name (I wouldn&#8217;t <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) you can add a rewite rule on your htaccess file:</p>
<blockquote><p>RewriteRule ^images\/crop\/([^/]+)\/([^/]+)\/(.+)$ cropimage.php?src=$3&amp;size=$2&amp;id=$1&amp;rewrite=1 [L,QSA]</p></blockquote>
<p>With this rule you can use something like: http://www.example.com/images/crop/1234/320&#215;180/my-awesome-image.png</p>
<p>Now on the script itself you need to do some adjustments on line &#8220;$_GET['src'] = &#8216;img/&#8217;.$_GET['id'].&#8217;/&#8217;.$_GET['src'];&#8221; where you point the image name to the respective folder.</p>
<p>If you want the original size just call it like this:</p>
<p>http://www.example.com/images/crop/1234/original/my-awesome-image.png</p>
<p>Note: using an ID is very important since it will prevent image overwriting.</p>
<p>&nbsp;</p>
<h2>Using with memcache:</h2>
<p>This script works great with memcache and apc, and it&#8217;s highly recommended!<br />
For that just set &#8220;define(&#8220;USE_MEMCACHE&#8221;, true);&#8221; to true (as it is on this example).</p>
<p>Using with APC:</p>
<p>This script works great with memcache and apc, and it&#8217;s highly recommended!<br />
For that just set &#8220;define(&#8220;USE_APC&#8221;, true);&#8221; to true (as it is on this example).</p>
<p>&nbsp;</p>
<h2>Watermark</h2>
<p>This script also supports a watermark.<br />
If you want to have a go with the watermark just set &#8220;define(&#8220;USE_WATERMARK&#8221;, false);&#8221; to true and set the path to the watermark in &#8220;define(&#8220;WATERMARK&#8221;,&#8221;);&#8221;.</p>
<p>&nbsp;</p>
<h2>Fork me @ <a title="Fork me at github" title='Original Link: http://bit.ly/odG98h'  href="http://www.joseairosa.com/?ZIRorxnx">http://bit.ly/odG98h</a></h2>
<p>&nbsp;</p>
<h2>Examples</h2>
<p>You can see it in action here: http://www.porvocacao.com<br />
In this website we&#8217;re using this script in memcache mode.</p>
<p>Let me know your thoughts <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2011/08/03/php-cropimage-script-memcache-and-apc-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP-RESTful WordPress Plugin</title>
		<link>http://www.joseairosa.com/2010/06/29/wp-restful-wordpress-plugin/</link>
		<comments>http://www.joseairosa.com/2010/06/29/wp-restful-wordpress-plugin/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 10:56:51 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restful]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=246</guid>
		<description><![CDATA[Hello! I&#8217;m 99% sure that you already heard about APIs or REST APIs, it&#8217;s what Twitter, flickr and a lot more companies use to share they&#8217;re resources with a consumer. A consumer can be anything from a website (for example, showing your Twitter updates on your blog or personal website) to a desktop / mobile [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>I&#8217;m 99% sure that you already heard about APIs or REST APIs, it&#8217;s what Twitter, flickr and a lot more companies use to share they&#8217;re resources with a consumer.<br />
A consumer can be anything from a website (for example, showing your Twitter updates on your blog or personal website) to a desktop / mobile application (iPhone, Android, Windows Mobile, &#8230;).<br />
This is possible because all information sent to and from the API is encoded in either two common, inter-platform language, XML and JSON.<br />
The difference between a regular API and a REST API is on the way they work. A REST API requires two entities to work, a client and a server.</p>
<h3><a title='Original Link: http://wordpress.org/extend/plugins/wp-restful/'  href="http://www.joseairosa.com/?Ndwkpfbo" target="_blank">Download WP-RESTful</a> <em>(Version 0.1)</em></h3>
<h3><a title='Original Link: http://wordpress.org/extend/plugins/wp-restful-users-plugin/'  href="http://www.joseairosa.com/?MHcP7Ghn" target="_blank">Download WP-RESTful Users Plugin</a> <em>(Version 0.1)</em></h3>
<h3><a title='Original Link: http://wordpress.org/extend/plugins/wp-restful-categories-plugin/'  href="http://www.joseairosa.com/?EyjonMf1" target="_blank">Download WP-RESTful Categories Plugin</a> <em>(Version 0.1)</em></h3>
<h3><a title='Original Link: http://wordpress.org/extend/plugins/wp-restful-tags-plugin/'  href="http://www.joseairosa.com/?tKIJ3z9F" target="_blank">Download WP-RESTful Tags Plugin</a> <em>(Version 0.1)</em></h3>
<h2 style="margin-top: 15px;"><em><strong>Follow me for  real-time updates</strong></em></h2>
<p><a title='Original Link: http://twitter.com/joseairosa'  href="http://www.joseairosa.com/?cXam8aSF">Twitter</a></p>
<h2 style="margin-top: 15px;"><em><strong>How does it work?</strong></em></h2>
<p>WP-RESTful uses OAuth, a widely, commonly and open source API implementation used all over the World (Wide Web).<br />
The way it work is fairly simple.</p>
<p>First a Consumer registers with a Server. At this point the Server will provide the Consumer with 2 tokens, a public and a private token. The public token will be used to communicate and identify the Consumer with the Server while the private token will be stored locally for security and integrity reasons.<br />
After this the Consumer will request the Server with a Request Token. This Request Token will be used to initiate the Authentication Protocol in where the Consumer will be required to authorize the Server.<br />
The Server will create 2 new token (definitive tokens). They will be our authentication tokens.</p>
<p>I know this sounds and seems complicated but you won&#8217;t need to do anything as the Plugin will do almost everything for you (Registration and Authentication process are manual).</p>
<h2 style="margin-top: 15px;"><em><strong>Plugin features</strong></em></h2>
<ul>
<li>Add new Plugins to API Plugin to extend functionalities to any way you want/need. (See next group)</li>
<li>Fully manageable Client and Server side.</li>
<li>Ability to choose what fields are allowed to be returned to the consumer.</li>
<li>Ability to restrict modules to OAuth authentication process or liberated them and make them open.</li>
<li>Load balance system where you can specify how many requests a given consumer is allowed in a 60 minute timeframe.</li>
<li>Out of the box Post and Comments management.</li>
<li>And much more&#8230;</li>
</ul>
<h2 style="margin-top: 15px;"><em><strong>Plugins</strong></em></h2>
<p>As stated on &#8220;Plugin Features&#8221; you have the ability to develop and/or add new modules to your REST API. This means, for example, if you use a plugin like WP E-Commerce, you can develop a plugin for the REST API in order to provide support for WP E-Commerce resources.<br />
The way these plugins are developed is very similar to how plugins for WordPress are developed.<br />
You can see this video that explains how plugins work and how you can develop them.</p>
<h2 style="margin-top: 15px;"><em><strong>Requirements?</strong></em></h2>
<p>All requirements for the plugin  to work properly are addressed by the plugin itself, upon activation.  You can see your system status on WP-RESTful link after activation the  plugin.</p>
<h2 style="margin-top: 15px;"><em><strong>How to install?</strong></em></h2>
<p>This plugin is installed like any other WordPress plugin out there.</p>
<ol>
<li>First you need to download it from WordPress Plugin Repository.</li>
<li>Upload the contents of the compacted file to your plugin folder on  your WordPress installation.</li>
<li>Go to your WordPress Administration page and activate the Plugin (Plugins → Installed → WP-RESTful → Activate)</li>
<li>Create a new page, name it API, set the permalink to /api and set the content as &#91;REST_return&#93; and save the page.</li>
<li>Go to WP-RESTful → WP-RESTful to check your system status.</li>
</ol>
<h2 style="margin-top: 15px;"><em><strong><em><strong>I need  help!</strong></em></strong></em></h2>
<p>Check these two videos. They will help you starting up.</p>
<div style="margin: 10px 0;"><object width="556" height="438"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=12940958&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=12940958&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="556" height="438"></embed></object>
<p><a title='Original Link: http://vimeo.com/12940958'  href="http://www.joseairosa.com/?byFNurYF">WP-RESTful &#8211; Starting and setting up</a> from <a title='Original Link: http://vimeo.com/joseairosa'  href="http://www.joseairosa.com/?QcbEwEWF">José Airosa</a> on <a title='Original Link: http://vimeo.com'  href="http://www.joseairosa.com/?tz2GLZGJ">Vimeo</a>.</p>
</div>
<div style="margin: 10px 0;"><object width="556" height="438"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=12941005&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=12941005&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="556" height="438"></embed></object>
<p><a title='Original Link: http://vimeo.com/12941005'  href="http://www.joseairosa.com/?TljfG9PY">WP-RESTful &#8211; Working with Plugins</a> from <a title='Original Link: http://vimeo.com/joseairosa'  href="http://www.joseairosa.com/?QcbEwEWF">José Airosa</a> on <a title='Original Link: http://vimeo.com'  href="http://www.joseairosa.com/?tz2GLZGJ">Vimeo</a>.</p>
</div>
<p>This post will be updated, if needed, to reflect changes made to the  plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2010/06/29/wp-restful-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>71</slash:comments>
		</item>
		<item>
		<title>WordPress Plugin &#8211; Parallel Loading System</title>
		<link>http://www.joseairosa.com/2010/05/17/wordpress-plugin-parallel-loading-system/</link>
		<comments>http://www.joseairosa.com/2010/05/17/wordpress-plugin-parallel-loading-system/#comments</comments>
		<pubDate>Mon, 17 May 2010 17:04:21 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[image optimization]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[speed improve]]></category>
		<category><![CDATA[system]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=138</guid>
		<description><![CDATA[The WP-PLS (short for Parallel Loading System) is a WordPress plugin that will enhance the loading efficiency of your Blog. It's very simple to use and it will require a small amount of time to configure in the start.]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>The WP-PLS (short for Parallel Loading System) is a WordPress plugin that will enhance the loading efficiency of your Blog. It&#8217;s very simple to use and it will only require a small amount of time to configure at the start.</p>
<h3><a title='Original Link: http://wordpress.org/extend/plugins/parallel-loading-system/'  href="http://www.joseairosa.com/?aLdgCt33" target="_blank">Download from WordPress Plugin Repository</a> <em>(Updated to version 0.1.8)</em></h3>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>Follow me for real-time updates</strong></em></h2>
<p><a title='Original Link: http://twitter.com/joseairosa'  href="http://www.joseairosa.com/?cXam8aSF">Twitter</a></p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>Why use it?</strong></em></h2>
<p>If you have an image intensive Blog, or even if you don&#8217;t, this plugin will boost the loading time of your Blog. The more images you have the more it will improve.</p>
<p>The amount of people that will visit your website for the first time or visit with an empty cache or disabled cache is huge, therefore, the best your website performs on that first visit the more chances that person will remain to view your website.</p>
<p>It is also known that nowadays, Google (and other search engines), are taking into account, for ranking purposes, your website page speed. Google Bot does not conserve a cache when it visits your website, so, the faster your website loads the more chances you have to rank higher.</p>
<p>This plug will <strong><span style="text-decoration: underline;">not</span></strong> change anything on your Blog. Every change that it makes will be processed in real time, right before the HTML code of your Blog is sent to the browser.</p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>How does it work?</strong></em></h2>
<p>Standard HTTP v1.1 requests only allow 2 connections, at the same time, from the same  domain.</p>
<p>This plugin will virtualize connections, through defined  subdomains. You can have as many subdomains as you like, but I do  recomend using a maximum of 5.</p>
<p style="text-align: center;"><a href="http://www.joseairosa.com/wp-content/uploads/2010/05/plugin1-e1274117124373.jpg"><img class="size-full wp-image-156 aligncenter" title="WP-PLS Comparison" src="http://www.joseairosa.com/wp-content/uploads/2010/05/plugin1-e1274117124373.jpg" alt="WP-PLS Comparison" width="551" height="223" /></a></p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>Requirements?</strong></em></h2>
<p>The plugin is programmed to be aware of this requirements, and if not fulfilled it will not change anything on your Blog.<br />
<span style="text-decoration: underline;">It will not break your Blog code!</span></p>
<ul>
<li>Your server needs to have a working <a title='Original Link: http://php.net/manual/en/book.image.php'  href="http://www.joseairosa.com/?tjCK3N_W">GD Library</a> module for  PHP.</li>
<li>You should have a PHP installation with a minimum version of <strong>5.1.3</strong></li>
<li>Access to your server Administration Painel (cPanel, DirectAdmin, Plesk) in order to create new sub-domains for your domain.<br />
Lets say your domain is <strong>wp-pls.com</strong>. You will need to create domains like<br />
image1.<strong>wp-pls.com</strong><br />
image2.<strong>wp-pls.com</strong><br />
&#8230;</li>
</ul>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>How to install?</strong></em></h2>
<p>This plugin is installed like any other WordPress plugin out there.</p>
<ol>
<li>First you need to download it from WordPress Plugin Repository.</li>
<li>Upload the contents of the compacted file to your plugin folder on your WordPress installation.</li>
<li>Go to your WordPress Administration page and activate the Plugin (Plugins → Installed → WP-PLS → Activate)</li>
<li>Go to Settings → Parallel Loading System</li>
</ol>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>Plugin features?</strong></em></h2>
<p>Some of the features that you can expect when using this plugin:</p>
<ul>
<li>Automatic Image Optimization.</li>
<li>Parallelize HTTP connections.</li>
<li>Page speed improvement.</li>
<li>Auto-Path find (Automatically find server root path, sub-domain path, plugin resources path&#8230;).</li>
<li>Cache loss minimization.</li>
<li>Sub-domain real-time health tracking.</li>
<li>Auto recovery from resource files bad sync.</li>
<li>Ability to activate / deactivate sub-domains</li>
<li>Plugin Updates aware. (automatically re-sync files and database after an update)</li>
</ul>
<h2 id="whats-in-the-cooking-pan" style="margin-top: 30px; margin-bottom: 10px;"><em><strong>What&#8217;s in the cooking pan?</strong></em></h2>
<p>This was only the first release of the plugin. I&#8217;ve got a lot of new ideas that I would like to see implemented on next releases.<br />
Some of them are:</p>
<ul>
<li>Also parallelize CSS and JavaScript loading.</li>
<li>Add support to also load external images. At the moment it will only load locally stored images.</li>
<li>Add real-time rewrite functions to CSS and JavaScript. That way, images that have been called from the CSS file will also be parallelized.</li>
<li>Overall improve of the code.</li>
<li>Add options to manage image quality rendering.</li>
<li>Bug fixes (when found or reported).</li>
<li>And much more&#8230;</li>
</ul>
<p>If you have any features that you would like to see implemented, please don&#8217;t hesitate to <a title='Original Link: #comments'  href="http://www.joseairosa.com/?SLazTfgR">comment this post</a>, <a title='Original Link: http://twitter.com/joseairosa'  href="http://www.joseairosa.com/?cXam8aSF" target="_blank">tweet me</a> or <a title='Original Link: mailto:me@joseairosa.com'  href="http://www.joseairosa.com/?gfylCmKb" target="_blank">mail me</a> <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong><em><strong>I need help!</strong></em></strong></em></h2>
<p>It&#8217;s normal if you run into problems and I&#8217;m here to tell you how to fix them.</p>
<p>If for any reason the plugin is telling you that it doesn&#8217;t have permissions to alter a given file you will need to access your server, using your favorite FTP Client (Filezilla, Cyberduck, FlashFXP&#8230;) and change the permissions of the file to <strong>777</strong>. You can revert them back to <strong>644</strong> (normal permissions of a file) after the plugin finishes the modifications.</p>
<p>If you get a sub-domain health notification stating that your sub-domain is returning a 500 HTTP error code the most probable explanation is that your sub-domain folder has <strong>777</strong> permissions. Revert them back to <strong>755</strong> and you should be fine.</p>
<p>If you have any further questions please don&#8217;t hesitate to <a title='Original Link: mailto:me@joseairosa.com'  href="http://www.joseairosa.com/?gfylCmKb">send me an email</a> or add a comment on this post.</p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong>Creating sub-domains on cPanel?</strong></em></h2>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/-6NeRF_G8EQ&amp;hl=pt_PT&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube.com/v/-6NeRF_G8EQ&amp;hl=pt_PT&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong><em><strong>Creating  sub-domains on Plesk?</strong></em></strong></em></h2>
<ol>
<li>Log in to Plesk</li>
<li>Once logged in, click the &#8216;Home&#8217; button in the left navigation  frame.</li>
<li>Click on the domain name you wish to create a subdomain for.</li>
<li>Click on the ‘Subdomains’ button. This will take you to the  subdomain manager.</li>
<li>Add a new subdomain by clicking the corresponding button (Add New  Subdomain).</li>
<li>Enter the subdomain in the associated field. The SSL support  checkbox is optional, and should be used if you intend on using SSL with  your subdomain.</li>
<li>If you’d like to use the same FTP information as your main domain to  access the subdomain, skip down to the ‘Services’ section. If not,  select the checkbox ‘Create a separate FTP user account for this  subdomain’. Enter an FTP username and password, along with a hard disk  quota. If you do not enter a hard disk quota, the subdomain will be  allowed to use all resources included with your main domain.</li>
<li>In the ‘Services’ section, it is advised to check all services. This  will ensure that your subdomain can support all the features our  hosting accounts offer.</li>
<li>Click the ‘OK’ button to create the subdomain.</li>
</ol>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong><em><strong>Creating  sub-domains on DirectAdmin?</strong></em></strong></em></h2>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/wUgb7KkKaiA&amp;hl=pt_PT&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="385" src="http://www.youtube.com/v/wUgb7KkKaiA&amp;hl=pt_PT&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h2 style="margin-top: 30px; margin-bottom: 10px;"><em><strong><em><strong>Creating  sub-domains on manually on your server?</strong></em></strong></em></h2>
<p>To create a sub-domain, if don&#8217;t use a Control Panel, edit your http.conf file (normally located on <em>/etc/http/conf/http.conf</em>) and add the following at the end:</p>
<p><code>NameVirtualHost *:443</code></p>
<p><code>&lt;VirtualHost *:80&gt;<br />
ServerName YOUR SUBDOMAIN<br />
DocumentRoot ROOT TO SUBDOMAIN PATH<br />
ErrorLog ROOT TO SUBDOMAIN LOG<br />
&lt;/VirtualHost&gt;</code></p>
<p><code>&lt;VirtualHost *:443&gt;<br />
ServerName YOUR SUBDOMAIN<br />
DocumentRoot ROOT TO SUBDOMAIN PATH (SSL)<br />
ErrorLog ROOT TO SUBDOMAIN LOG (SSL)<br />
&lt;/VirtualHost&gt;</code></p>
<p>This post will be updated, if needed, to reflect changes made to the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2010/05/17/wordpress-plugin-parallel-loading-system/feed/</wfw:commentRss>
		<slash:comments>196</slash:comments>
		</item>
		<item>
		<title>WP e-commerce SKU on variations</title>
		<link>http://www.joseairosa.com/2010/03/30/wp-e-commerce-sku-on-variations/</link>
		<comments>http://www.joseairosa.com/2010/03/30/wp-e-commerce-sku-on-variations/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 21:30:52 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[sku]]></category>
		<category><![CDATA[wordpress plugin]]></category>
		<category><![CDATA[wp e-commerce]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=124</guid>
		<description><![CDATA[UPDATE &#8211; 22/02/2011 Files for the 3.7.8 version of wp-e-commerce. I have provided only the altered files and full plugin if you just want to replace it.DON&#8217;T FORGET TO BACKUP FIRST!!Download &#8594; http://bit.ly/3-7-8-SKU UPDATE &#8211; 01/09/2010 If you need additions that are not contemplated in this fix package you can email me for a specific [...]]]></description>
			<content:encoded><![CDATA[<h2><strong>UPDATE &#8211; 22/02/2011</strong></h2>
<p>Files for the 3.7.8 version of wp-e-commerce. I have provided only the altered files and full plugin if you just want to replace it.<br/>DON&#8217;T FORGET TO BACKUP FIRST!!<br/><br/>Download &rarr; <a title='Original Link: http://bit.ly/3-7-8-SKU'  href="http://www.joseairosa.com/?2S2axg2s" target="_blank">http://bit.ly/3-7-8-SKU</a><br/></p>
<h2><em>UPDATE &#8211; 01/09/2010</em></h2>
<p>If you need additions that are not contemplated in this fix package you can email me for a specific quote.</p>
<h2><em>UPDATE &#8211; 18/05/2010</em></h2>
<p>There has been an update on wp-e-commerce a few days ago and if you have applied my add-on you&#8217;ll probably have problems with the plugin. Post a comment or <a title='Original Link: mailto:me@joseairosa.com'  href="http://www.joseairosa.com/?gfylCmKb">email me</a> if you&#8217;re having problems.</p>
<p>===============================</p>
<p>If you are using wp-ecommerce plugin for wordpress and you ran into some missing functionalities this might help you.</p>
<p>The specific mod I&#8217;ll show you today will enable you to specify SKU to any variation on any product on your system.</p>
<p>I don&#8217;t know how proficient your are on programming WordPress, but let me know if you run into any difficulty.</p>
<p>So, first of all you need to add a new field on your database on table <strong>wp_wpsc_variations_properties</strong> called &#8220;sku&#8221;. I added this field as <strong>varchar</strong> with a length of <strong>64 characters</strong>, but do adapt this one to fit your needs.</p>
<p><strong>Backup your e-commerce plugin folder.</strong></p>
<p><a title='Original Link: http://bit.ly/3-7-8-SKU'  href="http://www.joseairosa.com/?2S2axg2s">DOWNLOAD 3.7.8 FILES HERE</a></p>
<p>This should get you up and running. Let me know if you need anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2010/03/30/wp-e-commerce-sku-on-variations/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Screencast 1 &#8211; mod_rewrite and PHP</title>
		<link>http://www.joseairosa.com/2009/08/03/screencast-1-mod_rewrite-and-php/</link>
		<comments>http://www.joseairosa.com/2009/08/03/screencast-1-mod_rewrite-and-php/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 15:43:07 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Screencast]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=101</guid>
		<description><![CDATA[<object width="550" height="312"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5910332&#38;server=vimeo.com&#38;show_title=1&#38;show_byline=1&#38;show_portrait=0&#38;color=&#38;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5910332&#38;server=vimeo.com&#38;show_title=1&#38;show_byline=1&#38;show_portrait=0&#38;color=&#38;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="312"></embed></object><p><a href="http://vimeo.com/5910332">Screencast - mod_rewrite and PHP</a> from <a href="http://vimeo.com/user2086629">José Airosa</a> on <a href="http://vimeo.com">Vimeo</a>.</p>]]></description>
			<content:encoded><![CDATA[<p><object width="550" height="312"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5910332&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5910332&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="312"></embed></object>
<p><a title='Original Link: http://vimeo.com/5910332'  href="http://www.joseairosa.com/?BQM9HrN0">Screencast &#8211; mod_rewrite and PHP</a> from <a title='Original Link: http://vimeo.com/user2086629'  href="http://www.joseairosa.com/?WpMUt2Gj">José Airosa</a> on <a title='Original Link: http://vimeo.com'  href="http://www.joseairosa.com/?tz2GLZGJ">Vimeo</a>.</p>
<p>Hello folks!</p>
<p>This time, and for the first time, I bring you a screencast! It&#8217;s all about mod_rewrite and PHP. What it is, how can we use it and how can we integrate it to be used with PHP.</p>
<p>Below are the functions that i talked about in the screencast. Use them, or not, as you please.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code1'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1011"><td class="code" id="p101code1"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Get current page URL
 * 
 * @return string with paeg name
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> curPageURL<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pageURL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTPS&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTPS&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;on&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$pageURL</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$pageURL</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;://&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SERVER_PORT&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;80&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$pageURL</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SERVER_NAME&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SERVER_PORT&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$pageURL</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SERVER_NAME&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$pageURL</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Get current page script name
 * 
 * @return string with page script name
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> curPageScriptName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">return</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SCRIPT_NAME&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><a href="http://www.php.net/strrpos"><span style="color: #990000;">strrpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SCRIPT_NAME&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Get current page name
 * 
 * @return string with page script name
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> curPageName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">return</span> <a href="http://www.php.net/end"><span style="color: #990000;">end</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span>curPageURL<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Hope you&#8217;ll enjoy as much as I did making it <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Let me know your feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2009/08/03/screencast-1-mod_rewrite-and-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Image Scale&amp;Crop with Cache support in PHP</title>
		<link>http://www.joseairosa.com/2009/07/21/image-scalecrop-with-cache-support-in-php/</link>
		<comments>http://www.joseairosa.com/2009/07/21/image-scalecrop-with-cache-support-in-php/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 18:25:52 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=70</guid>
		<description><![CDATA[<img src="http://www.joseairosa.com/wp-content/themes/BlueGrey/images/post_crop.jpg" alt="Image Scale&#038;Crop with Cache support in PHP" />

Hello fellow readers!

Sorry for not posting anything for so long, but my work has been taking me most of my time... anyway.

Today we'll go over on creating a PHP Script that will resize and crop (if wanted) an image with the added support of cache.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.joseairosa.com/wp-content/themes/BlueGrey/images/post_crop.jpg" alt="Image Scale&#038;Crop with Cache support in PHP" /></p>
<p>Hello fellow readers!</p>
<p>Sorry for not posting anything for so long, but my work has been taking me most of my time&#8230; anyway.</p>
<p>Today we&#8217;ll go over on creating a PHP Script that will resize and crop (if wanted) an image with the added support of cache.</p>
<p>PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM. Even more convenient, PHP can output image streams directly to a browser. You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.</p>
<p>You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and JPEG2000 images.</p>
<p>For this to work you&#8217;ll need a PHP 4.3.0 version or greater. Check <a title='Original Link: http://www.libgd.org/'  href="http://www.joseairosa.com/?lzKcT9qW">http://www.libgd.org/</a> for more information.</p>
<p>This script will work in stages.</p>
<ul>
<li><strong>Stage 1:</strong> Read the image and check if it is present on our cache folder. If so we&#8217;ll just use the cached version. Take in account that even if you supply an image on an external source it will not check the image itself but rather the link, thus, no external connection is made.</li>
<li><strong>Stage 2:</strong> Start reading the source image and do the required operations of cropping and scaling.</li>
<li><strong>Stage 3:</strong> Apply the changes and create image resource (new one).</li>
<li><strong>Stage 4:</strong> Save image in cache and return the new image.</li>
</ul>
<p>Ok, enough with all this &#8220;mumbo jumbo&#8221; an lets get to action:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p70code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p702"><td class="code" id="p70code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Created and developed by José P. Airosa
 * 
 * This file will enable you to automaticaly resize images without loosing quality.
 * It uses a simple math formulas to calculate the desired final size and then rerenders the image.
 * 
 * The usage is very simples. On you HTML code just create an image and replace the src with cropimage.php?src=img/myimage.jpg&amp;size=320x240
 * 
 * src - the source of the image itself
 * size - the size that the image should have. If the size is not directly compatible with the original size it will display a simple background and the image with
 * the correct size on top.
 * 
 * Example: &lt;img src=&quot;cropimage.php?src=img/myimage.jpg&amp;size=320x240&quot; alt=&quot;&quot; /&gt;
 * 
 * If it's a square image you can just use myimage.jpg&amp;size=320 and it will make a 320x320 image.
 * 
 */</span>
<a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;memory_limit&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;64M&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> cropImage <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Initialize variables;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$imgSrc</span><span style="color: #339933;">,</span> <span style="color: #000088;">$myImage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cropHeight</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cropWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dif</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stage 2: Read the image and check if it is present on our cache folder. If so we'll just use the cached version. Take in account that even if you supply 
	 * an image on an external source it will not check the image itself but rather the link, thus, no external connection is made.
	 * 
	 * Also check what type of file we're working with. Different files, different methods.
	 * 
	 * @param $image The image that it's to crop&amp;scale
	 * @return nothing
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> setImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Your Image</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Getting the image dimensions</span>
		<a href="http://www.php.net/list"><span style="color: #990000;">list</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/getimagesize"><span style="color: #990000;">getimagesize</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Check what file we're working with</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//create image png</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myImage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecreatefrompng"><span style="color: #990000;">imagecreatefrompng</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Error: Cannot find image!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/imagealphablending"><span style="color: #990000;">imagealphablending</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myImage</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// setting alpha blending on</span>
			<a href="http://www.php.net/imagesavealpha"><span style="color: #990000;">imagesavealpha</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myImage</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// save alphablending setting (important)</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpg'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpeg'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpe'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//create image jpeg</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myImage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecreatefromjpeg"><span style="color: #990000;">imagecreatefromjpeg</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Error: Cannot find image!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Find biggest length</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// This will zoom in to 50% zoom (crop!)</span>
		<span style="color: #000088;">$cropPercent</span> <span style="color: #339933;">=</span> <span style="color:#800080;">.5</span><span style="color: #339933;">;</span> 
		<span style="color: #666666; font-style: italic;">// Get the size that you submitted for resize on the URL</span>
		<span style="color: #000088;">$both_sizes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Check if it was submited something like 50x50 and not only 50 (wich is also supported)</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// Apply the cropping formula</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropHeight</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">*</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$cropPercent</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropWidth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$cropPercent</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// Apply the cropping formula</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropHeight</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$cropPercent</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropWidth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">*</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$cropPercent</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropHeight</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$cropPercent</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropWidth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$biggestSide</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$cropPercent</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">// Getting the top left coordinate</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropWidth</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropHeight</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * From a file get the extension
	 * 
	 * @param $filename The filename
	 * @return string file extension
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> getExtension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/array_pop"><span style="color: #990000;">array_pop</span></a> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * For PNG files (and possibly GIF) add transparency filter
	 * 
	 * @param $new_image
	 * @param $image_source
	 * @return nothing
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> setTransparency<span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image_source</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$transparencyIndex</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolortransparent"><span style="color: #990000;">imagecolortransparent</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$image_source</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$transparencyColor</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'red'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'green'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'blue'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">255</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$transparencyIndex</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$transparencyColor</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolorsforindex"><span style="color: #990000;">imagecolorsforindex</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$image_source</span><span style="color: #339933;">,</span> <span style="color: #000088;">$transparencyIndex</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$transparencyIndex</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolorallocate"><span style="color: #990000;">imagecolorallocate</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$transparencyColor</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$transparencyColor</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'green'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$transparencyColor</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blue'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/imagefill"><span style="color: #990000;">imagefill</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$transparencyIndex</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/imagecolortransparent"><span style="color: #990000;">imagecolortransparent</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$transparencyIndex</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stage 3: Apply the changes and create image resource (new one).
	 * 
	 * @return nothing
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> createThumb<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$thumbSizex</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thumbSizey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$both_sizes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$thumbSizex</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$thumbSizey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecreatetruecolor"><span style="color: #990000;">imagecreatetruecolor</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$thumbSizex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbSizey</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$bg</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolorallocate"><span style="color: #990000;">imagecolorallocate</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/imagefill"><span style="color: #990000;">imagefill</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bg</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/imagecopyresampled"><span style="color: #990000;">imagecopyresampled</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myImage</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbSizex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbSizey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropWidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cropHeight</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'png'</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'transparent'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'transparent'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTransparency</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myImage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Stage 4: Save image in cache and return the new image.
	 * 
	 * @return nothing
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> renderImage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$image_created</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$size_string</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Content-type: image/png'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/imagepng"><span style="color: #990000;">imagepng</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009933; font-style: italic;">/**
			 * Save image to the cache folder
			 */</span>
			<a href="http://www.php.net/imagepng"><span style="color: #990000;">imagepng</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'img_cache/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$size_string</span><span style="color: #339933;">.</span><a href="http://www.php.net/end"><span style="color: #990000;">end</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpg'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpeg'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpe'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Content-type: image/jpeg'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/imagejpeg"><span style="color: #990000;">imagejpeg</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009933; font-style: italic;">/**
			 * Save image to the cache folder
			 */</span>
			<a href="http://www.php.net/imagejpeg"><span style="color: #990000;">imagejpeg</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'img_cache/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$size_string</span><span style="color: #339933;">.</span><a href="http://www.php.net/end"><span style="color: #990000;">end</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imgSrc</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		<a href="http://www.php.net/imagedestroy"><span style="color: #990000;">imagedestroy</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thumb</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Some variables needed for this to work. We set $size_string as global in order to access it on renderImage()</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$size_string</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Initialize our Crop Image class</span>
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> cropImage <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$size_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$both_sizes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$size_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$both_sizes</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$size_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009933; font-style: italic;">/**
 * Atempt to load our cached image. If we can't that means there is no cache for that image. If we find 
 * we'll just load that one adn won't even think about cropping and scaling.
 * 
 * Stage 1: Read the image and check if it is present on our cache folder. If so we’ll just use the cached version. 
 * Take in account that even if you supply an image on an external source it will not check the image itself but rather the link, thus, no external connection is made.
 */</span>
<span style="color: #000088;">$img_cached</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'img_cache/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$size_string</span><span style="color: #339933;">.</span><a href="http://www.php.net/end"><span style="color: #990000;">end</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'src'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img_cached</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$img_cached</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$myImage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecreatefrompng"><span style="color: #990000;">imagecreatefrompng</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$img_cached</span> <span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Error: Cannot find image!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Content-type: image/png'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/imagepng"><span style="color: #990000;">imagepng</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$myImage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$img_cached</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpg'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$img_cached</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpeg'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$img_cached</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'jpe'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$myImage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecreatefromjpeg"><span style="color: #990000;">imagecreatefromjpeg</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$img_cached</span> <span style="color: #009900;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Error: Cannot find image!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Content-type: image/jpeg'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/imagejpeg"><span style="color: #990000;">imagejpeg</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$myImage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<a href="http://www.php.net/imagedestroy"><span style="color: #990000;">imagedestroy</span></a> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$myImage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setImage</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'src'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createThumb</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderImage</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>All the code is commented and I think anyone will understand it pretty well.</p>
<p>A few things to take it into account. There should be a folder called &#8220;img_cache&#8221; with write permissions otherwise cache won&#8217;t work.</p>
<p>While loading external files is normal for the image to take a few seconds to appear. That&#8217;s only on the first time you access it. Next times it will just load the cached version directly.</p>
<p>That&#8217;s about it. Really simple script.. oh yeh, i&#8217;ve only added support for jpg and png, but i think that from the code I&#8217;ve given you can easily add support for the others. But if someone requires and is not able to do it, please do ask me and I&#8217;ll do it <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hope you enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2009/07/21/image-scalecrop-with-cache-support-in-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create a simple TagCloud in PHP</title>
		<link>http://www.joseairosa.com/2009/07/09/create-a-simple-tagcloud-in-php/</link>
		<comments>http://www.joseairosa.com/2009/07/09/create-a-simple-tagcloud-in-php/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 21:41:45 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.joseairosa.com/?p=51</guid>
		<description><![CDATA[<img src="http://www.joseairosa.com/wp-content/themes/BlueGrey/images/tagcloud_post.jpg" alt="Create a simple TagCloud in PHP" />

Ok, as for my first post after my away time I’ll be showing you how to make a… Yes you figured it out, a TagCloud.

A TagCloud is as you know a Cloud… with Tags… hum, for some reason I think you already knew that. Anyway, jokes aside, a TagCloud is one of the most powerful visual information display nowadays. It’s not a complex module, by the opposite, it’s very simple.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.joseairosa.com/wp-content/themes/BlueGrey/images/tagcloud_post.jpg" alt="Create a simple TagCloud in PHP" /></p>
<p>Ok, as for my first post after my away time I&#8217;ll be showing you how to make a&#8230; Yes you figured it out, a TagCloud.</p>
<p>A TagCloud is as you know a Cloud&#8230; with Tags&#8230; hum, for some reason I think you already knew that. Anyway, jokes aside, a TagCloud is one of the most powerful visual information display nowadays. It&#8217;s not a complex module, by the opposite, it&#8217;s very simple.</p>
<p>A normal TagCloud displays all tags, in alphabetic order and the font size varies in according to the amount of times that tag has been found in use. Imagine that you have &#8220;hello&#8221;, &#8220;this&#8221;, &#8220;is&#8221;, &#8220;jose&#8221;,&#8221;blog&#8221; as your tags. You would get something like:</p>
<div style="text-align: center; margin: 10px 0 10px 0;">
<p><span style="font-size: 12px;">hello</span> <span style="font-size: 8px;">this</span> <span style="font-size: 14px;">is</span> <span style="font-size: 22px;">jose</span> <span style="font-size: 18px;">blog</span></div>
<p>You would know that &#8220;jose&#8221; is the tag with most views (when we say views we can say records in a database).</p>
<div class="download_bt"><a title='Original Link: downloads/tagcloud.zip'  href="http://www.joseairosa.com/?YetJXmUt">Download source files and example</a></div>
<p>The installation of the module is very easy and all the required information can be found on the files that i provide.</p>
<p>Extra info:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p51code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p513"><td class="code" id="p51code3"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// This will create a TagCloud with default max font size and minimum font size. The default values can be set on file tagcloud.php in function create_tag_cloud($array,$limit_top_size = 38,$limit_low_size = 18)</span>
<span style="color: #000088;">$tag_size</span> <span style="color: #339933;">=</span> create_tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Or with specific values</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p51code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p514"><td class="code" id="p51code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$tag_size</span> <span style="color: #339933;">=</span> create_tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags_array</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Max font size will be 40 and minimum font size 10. (these are the max and min values allowed for TagCloud font fluctuation.</p>
<p>And there you go. Just style the code as you like.</p>
<p>PS: Yes, i know what you&#8217;re thinking, you can change the code as you please <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Let me know if you have any issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2009/07/09/create-a-simple-tagcloud-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A good way to create Logs in PHP</title>
		<link>http://www.joseairosa.com/2009/02/10/a-good-way-to-create-logs-in-php/</link>
		<comments>http://www.joseairosa.com/2009/02/10/a-good-way-to-create-logs-in-php/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 14:04:59 +0000</pubDate>
		<dc:creator>José P. Airosa</dc:creator>
				<category><![CDATA[Classes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[classes]]></category>

		<guid isPermaLink="false">http://localhost:8888/Blog/wordpress/?p=7</guid>
		<description><![CDATA[<img src="http://www.joseairosa.com/wp-content/themes/BlueGrey/images/post2.png" alt="A good way to create Logs in PHP" />

Hello everyone :)

Today we're gonna go over Logging in PHP as nested <a href="http://pt.php.net/zend-engine-2.php">Class</a>.

With the introduction of <a href="http://www.php.net/">PHP5</a> we now get the opportunity to use PHP as an <a href="http://en.wikipedia.org/wiki/Object-oriented_programming_language">Object Oriented Programming Language</a>. What this means is, and in a very short way, that we can now have a more reliable, faster and safer way to program in PHP.

OO programming brings <a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)">abstraction</a>, <a href="http://en.wikipedia.org/wiki/Information_hiding">encapsulation</a>, <a href="http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)">inheritance</a>, and <a href="http://en.wikipedia.org/wiki/Polymorphism_(computer_science)">polymorphism</a> so, therefore, PHP also does.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.joseairosa.com/wp-content/themes/BlueGrey/images/post2.png" alt="A good way to create Logs in PHP" /></p>
<p>Hello everyone <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Today we&#8217;re gonna go over Logging in PHP as nested <a title='Original Link: http://pt.php.net/zend-engine-2.php'  href="http://www.joseairosa.com/?M7h5Abzu">Class</a>.</p>
<p>With the introduction of <a title='Original Link: http://www.php.net/'  href="http://www.joseairosa.com/?F668TupL">PHP5</a> we now get the opportunity to use PHP as an <a title='Original Link: http://en.wikipedia.org/wiki/Object-oriented_programming_language'  href="http://www.joseairosa.com/?bfp5Pm9q">Object Oriented Programming Language</a>. What this means is, and in a very short way, that we can now have a more reliable, faster and safer way to program in PHP.</p>
<p>OO programming brings <a title='Original Link: http://en.wikipedia.org/wiki/Abstraction_(computer_science)'  href="http://www.joseairosa.com/?ACWiS0Fu">abstraction</a>, <a title='Original Link: http://en.wikipedia.org/wiki/Information_hiding'  href="http://www.joseairosa.com/?WMpmOOGi">encapsulation</a>, <a title='Original Link: http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)'  href="http://www.joseairosa.com/?KCgtWv4X">inheritance</a>, and <a title='Original Link: http://en.wikipedia.org/wiki/Polymorphism_(computer_science)'  href="http://www.joseairosa.com/?AiSevQvV">polymorphism</a> so, therefore, PHP also does.</p>
<ul>
<li>Abstraction &#8211; Allows the programmer to declare abstract methods that can be instantiated in a class and declared by an object.</li>
<li>Encapsulation &#8211; Gives us the ability to protect which ever data, inside a class, by using protected methods like private classes ou functions.</li>
<li>Inheritance &#8211; We can now create tree like class structure where the lower levels on the tree are childes of the level above. (in this Logging example we&#8217;re going to be using this methodology)</li>
<li>Polymorphism &#8211; Using this feature we&#8217;re able to declare a given class and use his children methods even tho we have declared parent class without the need to redeclare them.</li>
</ul>
<p>First of all we&#8217;re going to go over the basic structure of our Log class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p75"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p7code5"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> iLogs
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insereLog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$entrada</span><span style="color: #339933;">,</span><span style="color: #000088;">$tipo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We declared an interface. This way the application that will be calling this class is able to read its available content without the need to directly access the class internally.</p>
<blockquote><p><span style="font-weight:bold;">Note:</span> Methods that are declared on the interface need to be equal to the ones declared inside the class itself (either method name or number of arguments required). Otherwise you&#8217;ll get a fatal error from PHP.</p></blockquote>
<p>Next step takes us to declaration of the class itself.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p76"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p7code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Logs implements iLogs
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">const</span> VERBOSE <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// Max size for log compression -&gt; 1MB</span>
 <span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024000</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// Folder in your root where the logs will be stored</span>
 <span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$cwd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'logs/'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As you can see, we&#8217;re telling class Logs that it should <span style="font-style:italic;">implement</span> interface iLogs that we previously declared.</p>
<p>Every class needs a constructor and a destructor. Basically what should and should not be done when we initialize the class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p77"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p7code7"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_FILE_ADMIN'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_FILE_ADMIN'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'logAdmin.log'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_FILE_CLIENTES'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_FILE_CLIENTES'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'logClientes.log'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_FILE_WEBSERVICES'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOG_FILE_WEBSERVICES'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'logWebServices.log'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">preparaDirectorias</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">preparaLogs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a title='Original Link: http://pt2.php.net/manual/en/language.oop5.decon.php'  href="http://www.joseairosa.com/?hh307yjT">__construct</a> and <a title='Original Link: http://pt2.php.net/manual/en/language.oop5.decon.php'  href="http://www.joseairosa.com/?hh307yjT">__destruct</a> use &#8220;__&#8221; since they are native to PHP5 and are automatically called when a class is instantiated.</p>
<p>When the class is built we want to create some constants used throughout the class and we want to check if everything is according to the file structure required.<br />
We also use <span style="font-style:italic;">self</span> to address the actual instantiated class and :: in place of -> because we&#8217;ll be calling them in static mode (no data can be changed).</p>
<p>Our destruct class is empty since there is nothing to be done when the class is destroyed.</p>
<blockquote><p><span style="font-weight:bold;">Note:</span> Normally you can use this function for a DB connection and destruct can close the connection.</p></blockquote>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p78"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p7code8"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> preparaDirectorias<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <a href="http://www.php.net/chdir"><span style="color: #990000;">chdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_dir"><span style="color: #990000;">is_dir</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;logs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/mkdir"><span style="color: #990000;">mkdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'logs'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was no possible to create 'logs' dir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_dir"><span style="color: #990000;">is_dir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;logs_arquivo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/mkdir"><span style="color: #990000;">mkdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'logs_arquivo'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was no possible to create 'logs_arquivo' dir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We attempt to check if folder structure is properly created, if not we create it.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p79"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code" id="p7code9"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> preparaLogs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN <span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$max_size</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">compressbz2</span><span style="color: #009900;">&#40;</span>LOG_FILE_ADMIN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <a href="http://www.php.net/unlink"><span style="color: #990000;">unlink</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN <span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$max_size</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">compressbz2</span><span style="color: #009900;">&#40;</span>LOG_FILE_CLIENTES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <a href="http://www.php.net/unlink"><span style="color: #990000;">unlink</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$max_size</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">compressbz2</span><span style="color: #009900;">&#40;</span>LOG_FILE_WEBSERVICES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <a href="http://www.php.net/unlink"><span style="color: #990000;">unlink</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We&#8217;re going to check the size of our logs. If they exceed $max_size then we <a title='Original Link: http://en.wikipedia.org/wiki/Data_compression'  href="http://www.joseairosa.com/?_y5NcBWM">compress</a> them and create a new and fresh log file.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p710"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p7code10"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> compressbz2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$file_pointer</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//Opens the file in readonly,</span>
  <span style="color: #666666; font-style: italic;">//Check for permissions</span>
  <span style="color: #000088;">$file_read</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fread"><span style="color: #990000;">fread</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_pointer</span><span style="color: #339933;">,</span> <a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//Reads the content</span>
  <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_pointer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//Closes the file</span>
  <span style="color: #000088;">$actual</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-Ymd-His&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file_name</span><span style="color: #339933;">.</span><span style="color: #000088;">$actual</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.bz2&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//Opens compression file for writing purpose</span>
  <span style="color: #000088;">$bz</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/bzopen"><span style="color: #990000;">bzopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'logs_arquivo/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//Writes the file</span>
  <a href="http://www.php.net/bzwrite"><span style="color: #990000;">bzwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bz</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file_read</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//Closes the file</span>
  <a href="http://www.php.net/bzclose"><span style="color: #990000;">bzclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bz</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A simple function for compressing files. I will not go into a lot of detail on this section. If you find it to be useful please <a title='Original Link: mailto:joseairosa@core-creations.pt'  href="http://www.joseairosa.com/?335OoYAP">contact me</a> and I&#8217;ll make a post about file compression.</p>
<p>And finally we&#8217;re going to create the method that we call when using this class to add a log.</p>
<blockquote><p><span style="font-style:italic;">Note:</span> As you probably noticed (or not <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) all other methods (except construct and destruct) are private and therefore can only be called from within the class itself.</p></blockquote>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p711"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p7code11"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insereLog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$entrada</span><span style="color: #339933;">,</span><span style="color: #000088;">$tipo</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipo</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN <span style="color: #339933;">,</span> <span style="color: #0000ff;">'a+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_ADMIN <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'['</span><span style="color: #339933;">.</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y/m/d - H:i:s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'] '</span><span style="color: #339933;">.</span><span style="color: #000088;">$entrada</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span><span style="color: #009900;">&#41;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entrada</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipo</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #339933;">,</span> <span style="color: #0000ff;">'a+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_CLIENTES <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'['</span><span style="color: #339933;">.</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y/m/d - H:i:s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'] '</span><span style="color: #339933;">.</span><span style="color: #000088;">$entrada</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span><span style="color: #009900;">&#41;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entrada</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipo</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cwd</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES <span style="color: #339933;">,</span> <span style="color: #0000ff;">'a+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It was not possible to create '&quot;</span><span style="color: #339933;">.</span>LOG_FILE_WEBSERVICES <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'['</span><span style="color: #339933;">.</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y/m/d - H:i:s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'] '</span><span style="color: #339933;">.</span><span style="color: #000088;">$entrada</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEBUG</span><span style="color: #009900;">&#41;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entrada</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This logging class supports logs for 3 different types of systems; frontoffice (clients), backoffice (administrations) and <a title='Original Link: http://pt.wikipedia.org/wiki/Web_service'  href="http://www.joseairosa.com/?7hUrYec5">webservices</a>.</p>
<p>The way you call this function can be done in different ways, in this case, I&#8217;ll go over the Inheritance feature we talked before.</p>
<p>Imagine you have a class, lets say, foo</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p712"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p7code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// I bet you never seen this before!!! hehe ^_^</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello World'</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>What we can do is&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p7code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p713"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p7code13"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Logs.class.php is your Log class we just did</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Logs.class.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #000000; font-weight: bold;">extends</span> Logs <span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// I bet you never seen this before!!! hehe ^_^</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello World'</span><span style="color: #339933;">;</span>
  Logs<span style="color: #339933;">::</span><span style="color: #004000;">insereLog</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Mom, I think i just said Hello World. Log it please, thank you!&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And voila, there you go <img src='http://www.joseairosa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  your very own log system out of the box.</p>
<p>Feel free to report me any mistakes, suggestions or doubts you might have.</p>
<p>Have fun and <span style="font-style:italic;">be != be# {&#8216;run remotly&#8217; &#038;&#038; Get<All>['4_free'];}</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joseairosa.com/2009/02/10/a-good-way-to-create-logs-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

