<?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>Tech.Bitez &#187; PHP</title>
	<atom:link href="http://www.mwasif.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mwasif.com</link>
	<description>Bits and pieces of linux, mysql, apache, php</description>
	<lastBuildDate>Sun, 20 Jun 2010 10:07:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP sessions across subdomains</title>
		<link>http://www.mwasif.com/2008/16/php-sessions-across-subdomains/</link>
		<comments>http://www.mwasif.com/2008/16/php-sessions-across-subdomains/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 12:04:45 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php sessions]]></category>
		<category><![CDATA[php sessions across subdomains]]></category>
		<category><![CDATA[sessions across subdomains]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/?p=16</guid>
		<description><![CDATA[Share php sessions across subdomains.]]></description>
			<content:encoded><![CDATA[<p>If you are facing problems sharing sessions across subdomains, use the following code before session_start().</p>
<pre class="php"><a href="http://www.php.net/ini_set"><span style="color: #000066;">ini_set</span></a> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'session.cookie_domain'</span>, <span style="color: #ff0000;">'.mysite.com'</span> <span style="color: #66cc66;">&#41;</span>;</pre>
<p>Replace mysite.com with your domain name.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2008/16/php-sessions-across-subdomains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP 4 is dead, last release of PHP 4!!!</title>
		<link>http://www.mwasif.com/2008/13/php-4-is-dead-last-release-of-php-4/</link>
		<comments>http://www.mwasif.com/2008/13/php-4-is-dead-last-release-of-php-4/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 17:45:21 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php 4]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/?p=13</guid>
		<description><![CDATA[PHP 4 is dead now. There will be no more PHP 4 release available.]]></description>
			<content:encoded><![CDATA[<p>The last release of PHP 4 is now available for <a href="http://www.php.net/archive/2008.php#id2008-08-07-1">download</a> on 7th of August 2008. PHP 4 has been serving the web sites since 2000.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2008/13/php-4-is-dead-last-release-of-php-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Should we use template engines in PHP?</title>
		<link>http://www.mwasif.com/2008/10/should-we-use-template-engines-in-php/</link>
		<comments>http://www.mwasif.com/2008/10/should-we-use-template-engines-in-php/#comments</comments>
		<pubDate>Thu, 01 May 2008 08:50:40 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[smarty template engine]]></category>
		<category><![CDATA[template engines]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/2008/10/should-we-use-template-engines-in-php/</guid>
		<description><![CDATA[A forums discussion on using template engines in PHP]]></description>
			<content:encoded><![CDATA[<p>I came across <a href="http://www.sitepoint.com/forums/showthread.php?t=67849">this</a> discussion today on pros and cons of using template engines in PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2008/10/should-we-use-template-engines-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Increasing file upload limit in PHP</title>
		<link>http://www.mwasif.com/2008/8/increasing-file-upload-limit-in-php/</link>
		<comments>http://www.mwasif.com/2008/8/increasing-file-upload-limit-in-php/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 19:10:40 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/2008/8/increasing-file-upload-limit-in-php/</guid>
		<description><![CDATA[Increasing file upload limit in PHP, Apache (php.ini and .htaccess).]]></description>
			<content:encoded><![CDATA[<p>There are different options to increase file upload limit in PHP. First is changing PHP configuration file (php.ini) and restarting webserver or overwriting the php.ini value in .htacces (this option is available if you are running Apache).</p>
<p>There are 2 directives which affect upload limit i.e. upload_max_filesize and post_max_size.</p>
<p>Now we look at the first method. First you have to find out where the php.ini is. To find out the location, make a .php file containing only this code and place it in your webroot and point your browser to this file.</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/phpinfo"><span style="color: #000066;">phpinfo</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<p>In the page output you can find <em>Configuration File Path</em>. Open this file and change the values for upload_max_filesize and post_max_size according to your requirement e.g. to set 10MB upload limit, the values will be<br />
<strong>upload_max_filesize = 10M<br />
post_max_size = 10M</strong></p>
<p><span id="more-8"></span><br />
After changing the values, save php.ini and restart the webserver. If you open up the above PHP file again, you'll see the updated values of upload_max_filesize and post_max_size.</p>
<p>In case you don't have access to php.ini (in shared hosting environment) or don't want to restart the webserver then the best option is to use .htaccess. </p>
<p>The syntax for .htaccess as follows<br />
<strong>php_value upload_max_filesize 10M<br />
php_value post_max_size 10M</strong></p>
<p><a href="http://httpd.apache.org/">Apache</a> supports .htaccess. I am not sure if you can overwrite these settings in .htaccess with <a href="http://www.lighttpd.net/">lighttpd</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2008/8/increasing-file-upload-limit-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving images in MySQL with PHP</title>
		<link>http://www.mwasif.com/2007/4/save-image-in-mysql-with-php/</link>
		<comments>http://www.mwasif.com/2007/4/save-image-in-mysql-with-php/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 18:33:53 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php mysql image]]></category>
		<category><![CDATA[save image mysql]]></category>
		<category><![CDATA[save image php mysql]]></category>
		<category><![CDATA[save image with php]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/2007/4/save-image-in-mysql-with-php/</guid>
		<description><![CDATA[This is a short description how to save images in MySQL using PHP.]]></description>
			<content:encoded><![CDATA[<p>People have different opinions on saving images in database. Some says, "Why bother database if we can handle this by saving images to disk". I am agree with this;).</p>
<p>Most of the requirements can be fulfilled by saving the images to disk. This reduces the unnecessary load on MySQL.</p>
<p>Here is the small code to save the image in MySQL with the help of PHP.<br />
<span id="more-4"></span></p>
<p>Images are saved in MySQL as BINARY data. BINARY data can not be saved in varchar or char data types, for this purpose we need a data type which can handle binary data. <a href="http://dev.mysql.com/doc/refman/5.0/en/blob.html">BLOB</a> columns are treated as binary strings (byte strings). The following table is fulfilling our requirements for a simple test with a BLOB field.</p>
<pre class="mysql"><span style="color: #993333; font-weight: bold;">CREATE TABLE</span> `images` <span style="color: #66cc66;">&#40;</span>
  `id` <span style="color: #aa9933; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> <span style="color: #aa3399; font-weight: bold;">AUTO_INCREMENT</span>,
  `image` <span style="color: #aa9933; font-weight: bold;">MEDIUMBLOB</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span>,
  <span style="color: #993333; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #66cc66;">&#40;</span>`id`<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE=MyISAM;</pre>
<p>Now we have a MySQL table ready to store the image. Next steps are easy i.e.</p>
<ol>
<li>Read the image</li>
<li>Encode the image data</li>
<li>Save binary data in DB</li>
</ol>
<p>These 3 steps are performed with the following PHP code</p>
<pre class="php"><span style="color: #0000ff;">$image</span> = <a href="http://www.php.net/chunk_split"><span style="color: #000066;">chunk_split</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/base64_encode"><span style="color: #000066;">base64_encode</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;image.jpg&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">&quot;INSERT INTO images (image) VALUES('$image')&quot;</span>;
<a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span> or <a href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_error"><span style="color: #000066;">mysql_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Image id is &quot;</span>.<a href="http://www.php.net/mysql_insert_id"><span style="color: #000066;">mysql_insert_id</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Now we have saved the image in database successfully. The next step is to display the image.</p>
<pre class="php"><span style="color: #808080; font-style: italic;">// showimage.php</span>
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Content-type: image/jpeg'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">&quot;SELECT image from images where id=1&quot;</span>;
<span style="color: #0000ff;">$rs</span> = <a href="http://www.php.net/mysql_fetch_array"><span style="color: #000066;">mysql_fetch_array</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/base64_decode"><span style="color: #000066;">base64_decode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rs</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;image&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Ohhh!!! You wanted to display the image in HTML page. No problem, call this file as a image in &lt;img&gt; .e.g.</p>
<pre class="html4strict"><span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">&lt;title&gt;</span></a></span>Image Test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">&lt;h1&gt;</span></a></span>Displaying image from database<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1&gt;</span></span>
&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;showimage.php&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span></pre>
<p><a href='http://www.mwasif.com/wp-content/uploads/2007/07/multiple_files_upload.zip'>Download multiple files upload script</a></p>
<p>Let me know if you need some more info on this topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2007/4/save-image-in-mysql-with-php/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Download data as csv using PHP</title>
		<link>http://www.mwasif.com/2007/5/download-data-csv-using-php/</link>
		<comments>http://www.mwasif.com/2007/5/download-data-csv-using-php/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 23:05:50 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/2007/5/download-data-in-csv-format-using-php/</guid>
		<description><![CDATA[This is a very simple example to download data in csv format using PHP and MySQL. I have used a table with two columns i.e. id and name.
The main point to download file is a proper use of header(). It has said many times in many places but I repeat here, "Make sure there must [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very simple example to download data in csv format using PHP and MySQL. I have used a table with two columns i.e. id and name.</p>
<p>The main point to download file is a proper use of <a href="http://www.php.net/header">header()</a>. It has said many times in many places but I repeat here, "Make sure there must not be any sort of output (including whitespaces) before header()". We can also set a default file name for the file.</p>
<p>Here is the PHP code<br />
<span id="more-5"></span></p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">// Connect to database</span>
<a href="http://www.php.net/mysql_connect"><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;localhost&quot;</span>, <span style="color: #ff0000;">&quot;root&quot;</span>, <span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/mysql_select_db"><span style="color: #000066;">mysql_select_db</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// mention the file name to display in download prompt</span>
<span style="color: #0000ff;">$file_name</span> = <span style="color: #ff0000;">&quot;download.csv&quot;</span>;
&nbsp;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: application/octet-stream&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>$file_name<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Cache-Control: cache, must-revalidate&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Pragma: public&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Output header</span>
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Id,Name&quot;</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #0000ff;">$result</span> = <a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SELECT * FROM test&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rs</span> = <a href="http://www.php.net/mysql_fetch_array"><span style="color: #000066;">mysql_fetch_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$rs</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">&quot;,&quot;</span>;
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$rs</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<p>Consider the followings when downloading a large csv file</p>
<ol>
<li>PHP script may exceed maximum execution time. To prevent this, use <a href="http://www.php.net/set_time_limit">set_time_limit()</a> at top of the script.</li>
<li>Sometimes it is beneficial to use <a href="http://www.php.net/mysql_unbuffered_query">mysql_unbuffered_query()</a> instead of mysql_query() for huge data.</li>
</ol>
<p>If you find any problem with this code, please inform.</p>
<p><strong>Note:</strong> Do not use "ID" in the start of CSV file. Doing so will result in an error "<a href="http://support.microsoft.com/kb/323626">SYLK: File format is not valid</a>" when opening this file in Microsoft Excel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2007/5/download-data-csv-using-php/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Enable register globals</title>
		<link>http://www.mwasif.com/2007/3/enable-register-globals/</link>
		<comments>http://www.mwasif.com/2007/3/enable-register-globals/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 13:49:23 +0000</pubDate>
		<dc:creator>Wasif</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mwasif.com/2007/3/enable-register-globals/</guid>
		<description><![CDATA[You can enable register globals in many ways including php.ini, .htaccess and using PHP code even on shared host.]]></description>
			<content:encoded><![CDATA[<p>It is strongly recommended that you do not turn on the register_globals. But if you still want to turn on register_globals then follow these steps</p>
<p>Make a .php file containing only this code </p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/phpinfo"><span style="color: #000066;">phpinfo</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<p>And upload this file to your new server and open in the browser. In the page output find the value for 'register_globals'. If it is off, then you can solve this problem in the following ways</p>
<p><span id="more-3"></span></p>
<ol>
<li>Turn on the register_globals in php.ini by<br />
<strong>register_globals = On</strong><br />
(it will not be possible if you are on a shared web server) </li>
<li>Put extract($_REQUEST) on the top of every .php file.</li>
<li>Turn on register_globals using .htaccess make a text file with the name .htaccess and put the following code in it and upload to the root folder<br />
<strong>php_flag register_globals on</strong><br />
If you already have a .htaccess file in your website, then simply put this code in it.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.mwasif.com/2007/3/enable-register-globals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
