<?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>BLOGS@DiGiTSS &#187; PHP</title>
	<atom:link href="http://blogs.digitss.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.digitss.com</link>
	<description>DiGiTSS Team&#039;s Programming experience with PHP, MySQL, Ajax, Javascript, jQuery, C# and Microsoft technologies</description>
	<lastBuildDate>Sat, 13 Aug 2011 06:26:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Truncate last N lines of a file using PHP</title>
		<link>http://blogs.digitss.com/php/truncate-last-n-lines-of-a-file-using-php/</link>
		<comments>http://blogs.digitss.com/php/truncate-last-n-lines-of-a-file-using-php/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 17:03:52 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=600</guid>
		<description><![CDATA[For one of my project I needed to remove certain footer / tail-end lines from the file to make it clean as it was containing some summary of records within the file. Because if I do that it can be directly loaded into database by LOAD DATA command. To remove lines from the end of file you can use following snippet of code:]]></description>
			<content:encoded><![CDATA[<p>For one of my project I needed to remove certain footer / tail-end lines from the large-file to make it clean as it was containing some summary of records within the file. Because if I do that it can be directly loaded into database by <a title="Export/Import CSV files with MySQL – No external tool required" href="http://blogs.digitss.com/database/mysql/export-import-csv-files-with-mysql-no-external-tool-required/" target="_blank">LOAD DATA</a> command.</p>
<p>Usually one can read file into an array using PHP's <strong>file</strong> function but that's okay when size of file is in few hundred KB, if your file-size is running in to few MB to few hundred MB we need to find and use some efficient way to play with them. Because with large file reading as an array we can (and certainly will) run into memory outage issue.</p>
<p>To remove lines from the end of file you can use following snippet of code:</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// Function to truncate last N lines from the file</span>
<span style="color: #000000; font-weight: bold;">function</span> truncate_last_n_lines_of_file<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span>, <span style="color: #0000ff;">$lines_to_remove</span>, <span style="color: #0000ff;">$chunk</span> = <span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// Open file in read+write mode</span>
	<span style="color: #0000ff;">$handle</span> = @<a href="http://www.php.net/fopen"><span style="color: #000066;">fopen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span>, <span style="color: #ff0000;">&quot;a+&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$lines_found</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// Check if it's a valid file handle</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handle</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// size of file</span>
		<span style="color: #0000ff;">$max_length</span> = <span style="color: #0000ff;">$file_size</span> = <a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/intval"><span style="color: #000066;">intval</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file_size</span><span style="color: #66cc66;">&#41;</span> == PHP_INT_MAX<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$max_length</span> = PHP_INT_MAX;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// loop through file as long as we are not done with truncating required files</span>
		<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$length</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$length</span> &lt; <span style="color: #0000ff;">$max_length</span>; <span style="color: #0000ff;">$length</span> += <span style="color: #0000ff;">$chunk</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$max_length</span> - <span style="color: #0000ff;">$length</span><span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #0000ff;">$chunk</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0000ff;">$seek_size</span> = <span style="color: #0000ff;">$chunk</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0000ff;">$seek_size</span> = <span style="color: #0000ff;">$max_length</span> - <span style="color: #0000ff;">$length</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// read data in chunk</span>
			<a href="http://www.php.net/fseek"><span style="color: #000066;">fseek</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handle</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$length</span> + <span style="color: #0000ff;">$seek_size</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #cc66cc;">-1</span>, SEEK_END<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0000ff;">$data</span> = <a href="http://www.php.net/fread"><span style="color: #000066;">fread</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handle</span>, <span style="color: #0000ff;">$seek_size</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #0000ff;">$data</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Loop thorugh chunk to see if we are done with truncate</span>
			<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #0000ff;">$chunk</span>; <span style="color: #0000ff;">$i</span> &gt; <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span>--<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #cc66cc;">-1</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;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					<span style="color: #0000ff;">$lines_found</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$i</span>;
				<span style="color: #66cc66;">&#125;</span>
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lines_found</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #0000ff;">$lines_to_remove</span><span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					<a href="http://www.php.net/ftruncate"><span style="color: #000066;">ftruncate</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handle</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$max_length</span><span style="color: #66cc66;">&#41;</span> - <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$seek_size</span> - <span style="color: #0000ff;">$lines_found</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$lines_to_remove</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
			<a href="http://www.php.net/fclose"><span style="color: #000066;">fclose</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handle</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><span id="more-600"></span></p>
<p>How to use?</p>
<pre class="php"><span style="color: #808080; font-style: italic;">// To remove last 10 lines from the file</span>
truncate_last_n_lines_of_file<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;./data.txt&quot;</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>If you find this useful and come across some problem let me know or if you get a fix or do value addition, please add up as a comment.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/php/reading-mssql-blog-column-data-with-php/" rel="bookmark" title="April 1, 2011">Reading MSSQL BLOG column data with PHP</a></li>
<li><a href="http://blogs.digitss.com/programming/printing-data-table-vertically-why-and-how/" rel="bookmark" title="January 3, 2011">Printing data table vertically..! Why? and How?</a></li>
<li><a href="http://blogs.digitss.com/php/php-downloading-a-file-from-secure-website-https-using-curl/" rel="bookmark" title="October 25, 2008">PHP &#8211; Downloading a File from Secure website (https) using CURL</a></li>
<li><a href="http://blogs.digitss.com/php/php-performance-improvement-tips/" rel="bookmark" title="August 9, 2008">PHP: Performance Improvement Tips</a></li>
<li><a href="http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/" rel="bookmark" title="March 6, 2011">Posting or Uploading Files using cURL with PHP</a></li>
</ul>
<p><!-- Similar Posts took 12.900 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/truncate-last-n-lines-of-a-file-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading MSSQL BLOG column data with PHP</title>
		<link>http://blogs.digitss.com/php/reading-mssql-blog-column-data-with-php/</link>
		<comments>http://blogs.digitss.com/php/reading-mssql-blog-column-data-with-php/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 18:47:12 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=575</guid>
		<description><![CDATA[I was working on a migration script to transfer data from legacy desktop software to Portal we have developed. While migrating attachments (stored as TIFF files) in BLOB (Long Binary) in Microsoft SQL Database Server using PHP it was not a cake-walk. When I observed every time it was creating a file of same size (4KB). I quickly understood that there is some limitation (of size) for reading records in PHP configuration.]]></description>
			<content:encoded><![CDATA[<p>I was working on a migration script to transfer data from legacy desktop software to Portal we have developed. While migrating attachments (stored as TIFF files) in <strong>BLOB</strong> (Binary Large Object) in <strong>Microsoft SQL Database Server</strong> using <strong>PHP</strong> it was not a cake-walk. When I observed every time it was creating a file of same size (4KB). I quickly understood that there is some limitation (of size) for reading records in <strong>PHP</strong> configuration.</p>
<p>I searched through PHP.INI file and found following settings:</p>
<pre class="ini"><span style="color: #666666; font-style: italic;">; Valid range 0 - 2147483647.  Default = 4096.</span>
<span style="color: #666666; font-style: italic;">;mssql.textlimit = 4096</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Valid range 0 - 2147483647.  Default = 4096.</span>
<span style="color: #666666; font-style: italic;">;mssql.textsize = 4096</span></pre>
<p>I removed ";" and made values as zero, thinking that it will let PHP read unlimited size of data but didn't work out. So changed it to max value specified as following and worked perfect:<span id="more-575"></span></p>
<pre class="ini"><span style="color: #666666; font-style: italic;">; Valid range 0 - 2147483647.  Default = 4096.</span>
mssql.<span style="color: #000099;">textlimit </span>=<span style="color: #660066;"> <span style="">2147483647</span></span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Valid range 0 - 2147483647.  Default = 4096.</span>
mssql.<span style="color: #000099;">textsize </span>=<span style="color: #660066;"> <span style="">2147483647</span></span></pre>
<p>I was able to restore 4000+ <strong>BLOB</strong> records, creating 10GB of data on file-system with every file being migrated perfectly.</p>
<p>Did this post help you? or did you encountered similar problem? Please share your experience with us. As sharing is the karma of open-source developers like us.!<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/php/truncate-last-n-lines-of-a-file-using-php/" rel="bookmark" title="April 23, 2011">Truncate last N lines of a file using PHP</a></li>
<li><a href="http://blogs.digitss.com/database/mysql/using-views-to-avoid-cross-database-connection-mysql/" rel="bookmark" title="July 6, 2010">Using Views to avoid cross database connection &#8211; MySQL</a></li>
<li><a href="http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/" rel="bookmark" title="March 6, 2011">Posting or Uploading Files using cURL with PHP</a></li>
<li><a href="http://blogs.digitss.com/database/mysql/export-import-csv-files-with-mysql-no-external-tool-required/" rel="bookmark" title="November 14, 2009">Export/Import CSV files with MySQL &#8211; No external tool required</a></li>
<li><a href="http://blogs.digitss.com/php/my-experiences-with-soap-web-service-php-vs-net/" rel="bookmark" title="March 21, 2008">My experiences with SOAP Web-service PHP vs .NET</a></li>
</ul>
<p><!-- Similar Posts took 1446.192 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/reading-mssql-blog-column-data-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting or Uploading Files using cURL with PHP</title>
		<link>http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/</link>
		<comments>http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 18:40:33 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[cURL]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web Developer]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=561</guid>
		<description><![CDATA[cURL is very important tool for PHP programmers, we tends to do so many thing with using this tool. Posting data, imitating a form post and lot more, it's usage is countless. Some time back I came across situation where we have to post files to a 3rd party faxing service. I knew there are many possibilities but I didn't wanted to get into sockets and file stream to get this done, just wanted to post FILE in addition to rest of the post data.]]></description>
			<content:encoded><![CDATA[<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong></p>
<div id="attachment_563" class="wp-caption alignleft" style="width: 109px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/03/curl.png"><img class="size-full wp-image-563" title="cURL - groks those URLs" src="http://blogs.digitss.com/wp-content/uploads/2011/03/curl.png" alt="cURL - groks those URLs" width="99" height="37" /></a><p class="wp-caption-text">groks URLs</p></div>
<p></strong></p>
<p><strong> </strong></p>
<p><strong>cURL</strong> is very important tool for <strong>PHP</strong> programmers, we tends to do so many thing with using this tool. Posting data, imitating a form post and lot more, it's usage is countless. Some time back I came across situation where we have to post files to a 3rd party faxing service. I knew there are many possibilities but I didn't wanted to get into sockets and file stream to get this done, just wanted to post FILE in addition to rest of the post data.</p>
<pre class="php"><span style="color: #808080; font-style: italic;">// URL on which we have to post data</span>
<span style="color: #0000ff;">$url</span> = <span style="color: #ff0000;">&quot;http://localhost/tutorials/post_action.php&quot;</span>;
<span style="color: #808080; font-style: italic;">// Any other field you might want to catch</span>
<span style="color: #0000ff;">$post_data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;khan&quot;</span>;
<span style="color: #808080; font-style: italic;">// File you want to upload/post</span>
<span style="color: #0000ff;">$post_data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'file'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;@c:/logs.log&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Initialize cURL</span>
<span style="color: #0000ff;">$ch</span> = curl_init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Set URL on which you want to post the Form and/or data</span>
curl_setopt<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ch</span>, CURLOPT_URL, <span style="color: #0000ff;">$url</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Data+Files to be posted</span>
curl_setopt<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ch</span>, CURLOPT_POSTFIELDS, <span style="color: #0000ff;">$post_data</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Pass TRUE or 1 if you want to wait for and catch the response against the request made</span>
curl_setopt<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// For Debug mode; shows up any error encountered during the operation</span>
curl_setopt<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ch</span>, CURLOPT_VERBOSE, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// Execute the request</span>
<span style="color: #0000ff;">$response</span> = curl_exec<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ch</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Just for debug: to see response</span>
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span>;</pre>
<p>Above Code is the bare minimum required to post/upload file using CURL. As used in above example, it's not mandatory to use array index as "<strong>file</strong>". You can use anything required depending upon the requirement.</p>
<p>Posting multiple files is also easy, with the same code you can add multiple file upload using following lines:</p>
<pre class="php"><span style="color: #0000ff;">$post_data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'alian_error_log'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;@c:/alian_app_error.log&quot;</span>;
<span style="color: #0000ff;">$post_data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'myapp_error_log'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;@c:/myapp_error.log&quot;</span>;</pre>
<p>Here <strong>@</strong> is the key character, prefixing local file path with <strong>@</strong> does all the trick.</p>
<p>﻿<span id="more-561"></span></p>
<p><div id="attachment_562" class="wp-caption alignleft" style="width: 331px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/03/curl_post_result.png"><img class="size-full wp-image-562" title="cURL Post - as being received on posted URL" src="http://blogs.digitss.com/wp-content/uploads/2011/03/curl_post_result.png" alt="cURL Post - as being received on posted URL" width="321" height="308" /></a><p class="wp-caption-text">cURL Post - as being received on posted URL</p></div><br />
<!--adsense--></p>
<div style="clear:both">
For newbies cURL as it's described on <a title="cURL Project Home" href="http://curl.haxx.se/" target="_blank"><strong>cURL home</strong></a>:</p>
<blockquote><p>curl is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks.</p></blockquote>
</div>
<p>With <strong>PHP</strong> we can use <strong>cURL</strong> using <a title="libcurl for PHP" href="http://curl.haxx.se/libcurl/php/" target="_blank">libcurl extension for PHP</a>. It comes bundled with most of the <a title="Setting up PHP, MySQL, Apache with most up-to-date WAMP Package" href="http://blogs.digitss.com/php/setting-up-php-mysql-apache-with-most-up-to-date-wamp-package/">WAMP packages</a> and available on almost all managed/web hosting environments.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/php/php-downloading-a-file-from-secure-website-https-using-curl/" rel="bookmark" title="October 25, 2008">PHP &#8211; Downloading a File from Secure website (https) using CURL</a></li>
<li><a href="http://blogs.digitss.com/database/mysql/export-import-csv-files-with-mysql-no-external-tool-required/" rel="bookmark" title="November 14, 2009">Export/Import CSV files with MySQL &#8211; No external tool required</a></li>
<li><a href="http://blogs.digitss.com/javascript/simple-plain-ajax-without-any-javascript-library/" rel="bookmark" title="April 22, 2011">Simple / Plain Ajax &#8211; without any JavaScript library</a></li>
<li><a href="http://blogs.digitss.com/php/truncate-last-n-lines-of-a-file-using-php/" rel="bookmark" title="April 23, 2011">Truncate last N lines of a file using PHP</a></li>
<li><a href="http://blogs.digitss.com/programming/ag_e_parser_bad_property_value/" rel="bookmark" title="November 13, 2009">AG_E_PARSER_BAD_PROPERTY_VALUE</a></li>
</ul>
<p><!-- Similar Posts took 6621.794 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Setting up PHP, MySQL, Apache with most up-to-date WAMP Package</title>
		<link>http://blogs.digitss.com/php/setting-up-php-mysql-apache-with-most-up-to-date-wamp-package/</link>
		<comments>http://blogs.digitss.com/php/setting-up-php-mysql-apache-with-most-up-to-date-wamp-package/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 17:12:46 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Wamp]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=499</guid>
		<description><![CDATA[Availability of WAMP packages is not a new story, they are here since the beginning of last decade now. EasyPHP, Wamp, XAMPP and dozens of them. Find comparison of WAMP packages on Wikipedia here.]]></description>
			<content:encoded><![CDATA[<div id="attachment_514" class="wp-caption alignleft" style="width: 352px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/01/wamp-packages.gif"><img class="size-full wp-image-514" title="WAMP Packages" src="http://blogs.digitss.com/wp-content/uploads/2011/01/wamp-packages.gif" alt="WAMP Packages" width="342" height="70" /></a><p class="wp-caption-text">WAMP Packages</p></div>
<p>Availability of WAMP packages is not a new story, they are here since the beginning of last decade now. EasyPHP, Wamp, XAMPP and dozens of them. Find <a title="Comparison of WAMPs" href="http://en.wikipedia.org/wiki/Comparison_of_WAMPs" target="_blank">comparison of WAMP packages on Wikipedia here</a>.</p>
<p>We are here not to discuss all of them, just top 3 to 5 which are active and we can use them reliably for development or optionally for production purpose or both.</p>
<p>Having WAMP stake up-to-date on production environment is important as we are using open-source technologies and there are few to hundreds of critical to non-critical bugs are being fixed with every new release of the software, and if it's development environment we would like to test new features when they're hot.!</p>
<h4><strong><a title="Zend Server (License Edition)" href="http://www.zend.com/en/products/server/index" target="_blank">Zend Server</a>, <a title="Zend Server Cluster Manager" href="http://www.zend.com/en/products/server-cluster-manager/" target="_blank">Zend Server Cluster Manager</a> and <a title="Zend Server Community Edition" href="http://www.zend.com/en/products/server-ce/index" target="_blank">Zend Server Community Edition</a></strong>:</h4>
<div id="attachment_515" class="wp-caption alignleft" style="width: 168px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/01/zend-server-ce.jpg"><img class="size-full wp-image-515" title="Zend Server (CE)" src="http://blogs.digitss.com/wp-content/uploads/2011/01/zend-server-ce.jpg" alt="Zend Server (CE)" width="158" height="58" /></a><p class="wp-caption-text">Zend Server (CE)</p></div>
<p>All 3 editions are highly reliable and ready for production usage. I have tried both Zend Server and ZS-Community Edition, Zend Server - Commercial version is pre-tweaked for performance on production environment and Community Edition do not have some of the goodies. But that does not stop you or me from using Zend Server - CE on production. Zend Server comes with beautiful web-panel to administer, control and configure server from the browser itself. We can change PHP and Apache parameters, check server status and even restart service from within browser itself, this feature makes it good choice for remote server administration.</p>
<p>Zend Server - CE is as good for development as it is for production. It comes as Apache and PHP package where MySQL is an optional download during the installation wizard.</p>
<h4><strong><a title="The Uniform Server" href="http://www.uniformserver.com/" target="_blank">The Uniform Server</a></strong>:</h4>
<div id="attachment_516" class="wp-caption alignleft" style="width: 132px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/01/the-uniform-server.jpg"><img class="size-full wp-image-516" title="The Uniform Server" src="http://blogs.digitss.com/wp-content/uploads/2011/01/the-uniform-server.jpg" alt="The Uniform Server" width="122" height="53" /></a><p class="wp-caption-text">The Uniform Server</p></div>
<p>Uniform Server is comparatively new kid on the floor and highly configurable for both development and production use. It comes with system tray using which we can switch Apache and PHP configuration files from development to production or back and forth.</p>
<p>It comes in both VC6 and VC9 binaries for Windows and I must say it's most up-to-date WAMP package so far (I mean next or equal to Zend). Rest of all WAMP packages take week to months to bundle latest version of Apache, PHP or MySQL but I have observed Uniform Server very quick with that. This is main benefit if you are really looking for such option to use on production server.</p>
<p>Installation is simplest - extract and done. Comes with minimum, no big bucket (just 11-13MB in size).</p>
<p>Comes with some handy plug-ins for FTP, Resin, Tomcat etc. It has e-Accelerator packed with it is recommended for production use.</p>
<p><span id="more-499"></span></p>
<h4><strong><a title="WampServer Home" href="http://www.wampserver.com/" target="_blank">WampServer</a></strong>:</h4>
<div id="attachment_517" class="wp-caption alignleft" style="width: 196px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/01/wampserver.jpg"><img class="size-full wp-image-517" title="WampServer" src="http://blogs.digitss.com/wp-content/uploads/2011/01/wampserver.jpg" alt="WampServer" width="186" height="44" /></a><p class="wp-caption-text">WampServer</p></div>
<p>WampServer is decent Apache, MySQL and PHP stake, which comes as installer. Best part of it is that you can keep multiple version of PHP, Apache and MySQL over the same installation and at a time you can choose which version of A/M/P you want to run. It provides you wide variety of choice to choose from and we can always download newer version of PHP or MySQL or Apache and install as an add-on and if not suitable we can revert-back to older one just by a click or two.</p>
<p>Since last couple of years upgrades to components were slower and since Jan'11 I see some pace built-up. Recently included webGrind, X-debug etc in latest <em>WampServer 2.1e</em>, good for development will need some tweaking for usage in production.</p>
<h4><strong><a title="XAMPP from ApacheFriends" href="http://www.apachefriends.org" target="_blank">XAMPP</a></strong>:</h4>
<div id="attachment_518" class="wp-caption alignleft" style="width: 170px"><a href="http://blogs.digitss.com/wp-content/uploads/2011/01/xampp.gif"><img class="size-full wp-image-518" title="XAMPP - ApacheFriends" src="http://blogs.digitss.com/wp-content/uploads/2011/01/xampp.gif" alt="XAMPP - ApacheFriends" width="160" height="47" /></a><p class="wp-caption-text">XAMPP - ApacheFriends</p></div>
<p>This is my old companion for development machines and sometimes for production too. Though ApacheFriends do not recommend usage of XAMPP stake for production (it's for development and if you want to use for production use it at your own risk, but basically it's because of security reasons and default passwords and certain parameters in configs).</p>
<p>Comes in many packages for Mac, Linux and Windows so it's not just for Windows it's for all. It has been long time I have seen final version since XAMPP 1.7.3, which was released in Dec'09. Though it is active but recent version are still in <a title="XAMPP Beta" href="http://sourceforge.net/projects/xampp/files/BETAS/" target="_blank">beta</a> (it's too much, as it has been 2 years to a non-beta release).</p>
<p>It has flavors like Full, Lite and has plugins for Perl, Tomcat and many other goodies.</p>
<p><strong><span style="text-decoration: underline;">Finally</span>:</strong> After all we can use <strong>Zend Server</strong> or <strong>The Uniform Server</strong> for Production, while <strong>WampServer</strong> and <strong>XAMPP</strong> are good choice to kick-start the development as they come with lot of goodies. <strong>Zend</strong> does not release upgrades for <strong>Zend Server CE</strong> as they are only available for <em>Enterprise/Commercial Edition</em> along with support and other things. But it should be fine, as even if you go for any other choice upgrades will be manual only. When I say manual it will be replacing the current package and setting up your database and web-application on newer one again.</p>
<p>Though installing Apache, MySQL and PHP separately is also important, which will help us learn how they all are tied together.</p>
<p>I do not say other WAMP bundles are not good, but these 4 I have used personally for years and I like them. There are many teams and developer communities working hard to prepare similar WAMP packages and I respect all their hard-work and efforts and I am grateful to them for making our life easy.</p>
<p>Please share your feedback as comments on the article/post, share with friends if you like.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/php/beginner%e2%80%99s-resources-for-php-development/" rel="bookmark" title="February 15, 2008">Beginner&#8217;s Resources for PHP-MySQL Development</a></li>
<li><a href="http://blogs.digitss.com/php/php-527-is-released/" rel="bookmark" title="December 7, 2008">PHP 5.2.7 is released</a></li>
<li><a href="http://blogs.digitss.com/php/when-php-frameworks-are-going-to-stop-php-4-support/" rel="bookmark" title="August 15, 2009">When PHP Frameworks are going to stop PHP 4 support?</a></li>
<li><a href="http://blogs.digitss.com/news/mysql-5-5-available-for-production/" rel="bookmark" title="January 16, 2011">MySQL 5.5 available for production</a></li>
<li><a href="http://blogs.digitss.com/apache/installing-apache-on-windows-2008/" rel="bookmark" title="December 6, 2009">Installing Apache on Windows 2008</a></li>
</ul>
<p><!-- Similar Posts took 946.509 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/setting-up-php-mysql-apache-with-most-up-to-date-wamp-package/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 2 is just here &#8211; about to release..!</title>
		<link>http://blogs.digitss.com/php/codeigniter-2-is-just-here-about-to-release/</link>
		<comments>http://blogs.digitss.com/php/codeigniter-2-is-just-here-about-to-release/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 20:09:58 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[open-source]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=458</guid>
		<description><![CDATA[A well-known PHP Framework CodeIgniter which really do not need much introduction is about to release it's next major version CodeIgniter2.]]></description>
			<content:encoded><![CDATA[<div id="attachment_459" class="wp-caption alignleft" style="width: 285px"><a href="http://blogs.digitss.com/wp-content/uploads/2010/11/codeigniter.png"><img class="size-full wp-image-459" title="CodeIgniter - An MVC framework for PHP" src="http://blogs.digitss.com/wp-content/uploads/2010/11/codeigniter.png" alt="CodeIgniter - An MVC framework for PHP" width="275" height="90" /></a><p class="wp-caption-text">CodeIgniter - An MVC framework for PHP</p></div>
<p>I have been using <strong>CodeIgniter</strong> since some time and used in couple of my projects. It's a good and easy to use <strong>PHP MVC Framework</strong>, which takes you on the road very quickly and you start developing real time application with it. For any experienced PHP Programmer it's matter of few hours to start working with <strong>CI</strong> and get started-on with production.</p>
<p>It's got decent documentation (User Guide, Wiki and Community support forum). No configuration and no command-lines. Last release was way back in September'09 and I heard something about v1.8 sometime after that. But now it has been more than 1 year and recently while going through news section on <a title="CodeIgniter Home" href="http://codeigniter.com" target="_blank">CI website</a> I <a title="CodeIgniter News" href="http://codeigniter.com/news/whats_happening_now/" target="_blank">read a post</a> stating that new version of framework <strong>CI2</strong> is about to be released.</p>
<p>I got excited and downloaded a copy from <a title="CodeIgniter repository at bitbucket.org" href="http://bitbucket.org/ellislab/codeigniter" target="_blank">bitbucket</a>. I was happy to see that CodeIgniter2 will be dropping PHP4 support step by step. There are lot of new changes/additions which you might be interested in if you're day-to-day CI user. <strong>Ellislab</strong> being professional company <strong>CI2</strong> has been already used in their newer version of <strong>ExpressionEngine</strong>.</p>
<p>Here are some of the changes I have grabbed from <em><strong>CodeIgniter2 User Guide</strong></em>:</p>
<ul>
<li>General changes
<ul>
<li>PHP 4 support is deprecated.  Features new to 2.0.0 may not  support PHP 4, and all legacy features will no longer support PHP 4 as  of 2.1.0.<em> <span style="color: #008000;">(Good)</span></em></li>
<li>Scaffolding, having been deprecated for a number of versions, has been removed.</li>
<li>Plugins have been removed, in favor of Helpers.  The CAPTCHA plugin has been converted to a Helper and <a>documented</a>.   The JavaScript calendar plugin was removed due to the ready  availability of great JavaScript calendars, particularly with jQuery.</li>
<li>Added new special Library type: <a>Drivers</a>.</li>
<li>Moved the application folder outside of the system folder. <span style="color: #008000;"><em>(I liked this)</em></span></li>
<li>Added routing overrides to the main index.php file, enabling the normal routing to be overridden on a per "index" file basis.</li>
<li>Added the ability to set config values (or override config  values) directly from data set in the main index.php file.  This allows a  single application to be used with multiple front controllers, each  having its own config values.</li>
<li>Added <kbd>$config['directory_trigger']</kbd> to the config file so that a controller sub-directory can be specified when running _GET strings instead of URI segments.</li>
<li>Added ability to set "Package" paths - specific paths where the  Loader and Config classes should try to look first for a requested file.   This allows distribution of sub-applications with their own libraries,  models, config files, etc. in a single "package" directory.  See the <a>Loader class</a> documentation for more details.</li>
<li>In-development code is now hosted at <a href="http://bitbucket.org/ellislab/codeigniter/">BitBucket</a>. <span style="color: #008000;"><em>(Go grab your copy)</em></span></li>
<li>Removed the deprecated Validation Class.<span id="more-458"></span></li>
</ul>
</li>
<li>Libraries
<ul>
<li>Added <var>$prefix</var>, <var>$suffix</var> and <var>$first_url</var> properties to <a>Pagination library</a>.</li>
<li>Added the ability to suppress first, previous, next, last, and page links by setting their values to FALSE in the <a>Pagination library</a>.</li>
<li>Added <a>Security library</a>, which now contains the <dfn>xss_clean</dfn> function, <dfn>filename_security</dfn> function and other security related functions.</li>
<li>Added CSRF (Cross-site Reference Forgery) protection to the <a>Security library</a>.</li>
<li>Added <var>$parse_exec_vars</var> property to Output library.</li>
<li>Added ability to enable / disable individual sections of the <a>Profiler</a></li>
<li>Added a wildcard option <kbd>$config['allowed_types'] = '*'</kbd> to the <a>File Uploading Class</a>.</li>
<li>Added an 'object' config variable to the XML-RPC Server library  so that one can specify the object to look for requested methods,  instead of assuming it is in the $CI superobject.</li>
<li>Added "is_object" into the list of unit tests capable of being run.</li>
<li>Table library will generate an empty cell with a blank string, or NULL value.</li>
<li>Added ability to set tag attributes for individual cells in the Table library</li>
<li>Added a <kbd>parse_string()</kbd> method to the <a>Parser Class</a>.</li>
<li>Added HTTP headers and Config information to the <a>Profiler</a> output.</li>
<li>Added Chrome and Flock to the list of detectable browsers by <kbd>browser()</kbd> in the <a>User Agent Class</a>.</li>
<li>The <a>Unit Test Class</a> now has an optional "notes" field available to it, and allows for discrete display of test result items using <kbd>$this-&gt;unit-&gt;set_test_items()</kbd>.</li>
<li>Added a <kbd>$xss_clean</kbd> class variable to the XMLRPC library, enabling control over the use of the Security library's <kbd>xss_clean()</kbd> method.</li>
<li>Added a <kbd>download()</kbd> method to the <a>FTP library</a></li>
<li>Changed <kbd>do_xss_clean()</kbd> to return FALSE if the uploaded file fails XSS checks.</li>
<li>Added stripslashes() and trim()ing of double quotes from $_FILES type value to standardize input in Upload library.</li>
<li>Added a second parameter (boolean) to <kbd>$this-&gt;zip-&gt;read_dir('/path/to/directory', FALSE)</kbd> to remove the preceding trail of empty folders when creating a Zip  archive. This example would contain a zip with "directory" and all of  its contents.</li>
<li>Added ability in the Image Library to handle PNG transparency for resize operations when using the GD lib.</li>
<li>Modified the Session class to prevent use if no encryption key is set in the config file.</li>
<li>Added a new config item to the Session class <kbd>sess_expire_on_close</kbd> to allow sessions to auto-expire when the browser window is closed.</li>
<li>Improved performance of the Encryption library on servers where Mcrypt is available.</li>
<li>Changed the default encryption mode in the Encryption library to CBC.</li>
<li>Added an <kbd>encode_from_legacy()</kbd> method to provide a way to transition encrypted data from CodeIgniter 1.x to CodeIgniter 2.x. 				Please see the <a>upgrade instructions</a> for details.</li>
</ul>
</li>
<li>Database
<ul>
<li>Added <kbd>swap_pre</kbd> value to <a>database configuration</a>.</li>
<li>Added <kbd>autoinit</kbd> value to <a>database configuration</a>.</li>
<li>Added <kbd>stricton</kbd> value to <a>database configuration</a>.</li>
<li>Added <kbd>database_exists()</kbd> to the <a>Database Utilities Class</a>.</li>
<li>Semantic change to db-&gt;version() function to allow a list of  exceptions for databases with functions to return version string instead  of specially formed SQL queries. Currently this list only includes  Oracle and SQLite.</li>
<li>Fixed a bug where driver specific table identifier protection could lead to malformed queries in the <kbd>field_data()</kbd> functions.</li>
<li>Fixed a bug where an undefined class variable was referenced in database drivers.</li>
<li>Modified the database errors to show the filename and line number of the problematic query.</li>
<li>Removed the following deprecated functions: orwhere, orlike, groupby, orhaving, orderby, getwhere.</li>
<li>Removed deprecated _drop_database() and _create_database() functions from the db utility drivers.</li>
</ul>
</li>
<li>Helpers
<ul>
<li>Added <kbd>convert_accented_characters()</kbd> function to <a>text helper</a>.</li>
<li>Added accept-charset to the list of inserted attributes of <kbd>form_open()</kbd> in the <a>Form Helper</a>.</li>
<li>Deprecated the <kbd>dohash()</kbd> function in favour of <kbd>do_hash()</kbd> for naming consistency.</li>
<li>Non-backwards compatible change made to <kbd>get_dir_file_info()</kbd> in the <a>File Helper</a>.  No longer recurses 				by default so as to encourage responsible use (this function can cause server performance issues when used without caution).</li>
<li>Modified the second parameter of <kbd>directory_map()</kbd> in the <a>Directory Helper</a> to accept an integer to specify recursion depth.</li>
<li>Modified <kbd>delete_files()</kbd> in the <a>File Helper</a> to return FALSE on failure.</li>
<li>Added an optional second parameter to <kbd>byte_format()</kbd> in the <a>Number Helper</a> to allow for decimal precision.</li>
<li>Added alpha, and sha1 string types to <kbd>random_string()</kbd> in the <a>String Helper</a>.</li>
<li>Modified <kbd>prep_url()</kbd> so as to not prepend http:// if the supplied string already has a scheme.</li>
<li>Modified <kbd>get_file_info</kbd> in the file helper, changing filectime() to filemtime() for dates.</li>
<li>Modified <kbd>smiley_js()</kbd> to add optional third parameter to return only the javascript with no script tags.</li>
<li>The <kbd>img()</kbd> function of the <a>HTML helper</a> will now generate an empty string as an alt attribute if one is not provided.</li>
<li>If CSRF is enabled in the application config file, <kbd>form_open()</kbd> will automatically insert it as a hidden field.</li>
<li>Added <kbd>sanitize_filename()</kbd> into the <a>Security helper</a>.</li>
<li>Added <kbd>ellipsize()</kbd> to the <a>Text Helper</a></li>
<li>Added <kbd>elements()</kbd> to the <a>Array Helper</a></li>
</ul>
</li>
<li>Other Changes
<ul>
<li>Added an optional second parameter to <kbd>show_404()</kbd> to disable logging.</li>
<li>Updated loader to automatically apply the sub-class prefix as an  option when loading classes.  Class names can be prefixed with the  standard "CI_" or the same prefix as the subclass prefix, or no prefix  at all.</li>
<li>Increased randomness with <kbd>is_really_writable()</kbd> to avoid file collisions when hundreds or thousands of requests occur at once.</li>
<li>Switched some DIR_WRITE_MODE constant uses to FILE_WRITE_MODE where files and not directories are being operated on.</li>
<li><kbd>get_mime_by_extension()</kbd> is now case insensitive.</li>
<li>Added "default" to the list <a>Reserved Names</a>.</li>
<li>Added 'application/x-msdownload' for .exe files and ''application/x-gzip-compressed' for .tgz files to config/mimes.php.</li>
<li>Updated the output library to no longer compress output or send  content-length headers if the server runs with zlib.output_compression  enabled.</li>
<li>Eliminated a call to is_really_writable() on each request unless it is really needed (Output caching)</li>
<li>Documented <kbd>append_output()</kbd> in the <a>Output Class</a>.</li>
<li>Documented a second argument in the <kbd>decode()</kbd> function for the <a>Encryption Class</a>.</li>
<li>Documented db-&gt;close().</li>
<li>Moved _remove_invisible_characters() function from the <a>Security Library</a> to <a>common functions.</a></li>
</ul>
</li>
</ul>
<p>You can <a title="CodeIgniter2 Changelog" href="http://blogs.digitss.com/archives/codeigniter/codeigniter2-changelog.html" target="_blank">grab complete list of changes with bug-fixes here</a>. Though considering a major release I do not see any changes gives developer <strong>Wow...! experience</strong>..! majority were expected changes or enhancements over time.</p>
<p>It's not officially released yet but when we download it has User Guide ready and we may see few more changes before it gets officially available for production. But I am sure one can use it for production <em>(if had hands with CI previously or been PHP expert to take care if something goes unexpected.)</em></p>
<p>So did you got your hands on <strong>CodeIgniter2</strong>? How was your experience with <strong>CI</strong> so far?</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/php/php-downloading-a-file-from-secure-website-https-using-curl/" rel="bookmark" title="October 25, 2008">PHP &#8211; Downloading a File from Secure website (https) using CURL</a></li>
<li><a href="http://blogs.digitss.com/technology/hacking-jquery-thickbox/" rel="bookmark" title="April 27, 2008">Hacking jQuery Thickbox..!</a></li>
<li><a href="http://blogs.digitss.com/php/truncate-last-n-lines-of-a-file-using-php/" rel="bookmark" title="April 23, 2011">Truncate last N lines of a file using PHP</a></li>
<li><a href="http://blogs.digitss.com/news/netbeans-7-0-rc1-released/" rel="bookmark" title="April 4, 2011">Netbeans 7.0 RC1 Released</a></li>
<li><a href="http://blogs.digitss.com/programming/printing-data-table-vertically-why-and-how/" rel="bookmark" title="January 3, 2011">Printing data table vertically..! Why? and How?</a></li>
</ul>
<p><!-- Similar Posts took 11.821 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/codeigniter-2-is-just-here-about-to-release/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Smarty 3.0 is almost here..!</title>
		<link>http://blogs.digitss.com/php/smarty-3-0-is-almost-here/</link>
		<comments>http://blogs.digitss.com/php/smarty-3-0-is-almost-here/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 10:58:08 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Framework]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=432</guid>
		<description><![CDATA[There could be some or lot of us in PHP World who might have not heard about Smarty..! Yes, Smarty is the PHP Template Engine  since ages. Why Ages......? some of you might ask.. but it is there since long... really long, even before we started hearing about these PHP Frameworks.]]></description>
			<content:encoded><![CDATA[<div id="attachment_433" class="wp-caption alignleft" style="width: 260px"><a href="http://blogs.digitss.com/wp-content/uploads/2010/10/smarty-logo.gif"><img class="size-full wp-image-433" title="Smarty PHP Template Engine" src="http://blogs.digitss.com/wp-content/uploads/2010/10/smarty-logo.gif" alt="Smarty PHP Template Engine" width="250" height="64" /></a><p class="wp-caption-text">Smarty PHP Template Engine</p></div>
<p>There could be some or lot of us in <strong>PHP World</strong> who might have not heard about <strong>Smarty</strong>..! Yes, <strong>Smarty</strong> is the <strong>PHP Template Engine</strong> since ages. Why Ages......? some of you might ask.. but it is there since long... really long, even before we started hearing about these <strong><a title="PHP Frameworks" href="http://blogs.digitss.com/php/top-open-source-php-frameworks/" target="_self">PHP Frameworks</a></strong>.</p>
<p>I have been using <strong>Smarty</strong> in some of my projects and as part of my daily usage component I have been following up on the <a title="Smarty Home" href="http://www.smarty.net/" target="_blank">Smarty Website</a>. If you are like me you might have noticed that it has been more than one year <em>(8 beta and 3 rc releases)</em> that Smarty 3.0 is almost there and still there is no final release.</p>
<p>May be it's indication or beginning of the announcement of death of <strong>Only Template Engine PHP Frameworks</strong> or something else. Somehow community does not seems to be active or founders or whatever. Now a days many <strong>MVC frameworks</strong> are choice of developers and they either have in-built <strong>template-engine</strong> or no-template-engine or plug-in-support for <strong>template engines</strong>.</p>
<p>No matter what <strong>Smarty 3.0</strong> claims to be loaded with following features:<span id="more-432"></span></p>
<ul>
<li>PHP5 OO design</li>
<li>SPEED</li>
<li>Object Chaining</li>
<li>Exception Error Handling</li>
<li>Assigned Data Objects</li>
<li>Multiple Template Objects</li>
<li>Static Object Access</li>
<li>Pure PHP Template Option</li>
<li>Powerful Parser/Lexer</li>
<li>Tons of Template Syntax Enhancements</li>
<li>Improved Data Scoping Features</li>
<li>Variable Filters (ie. auto-html-escape)</li>
<li>In-template Functions (easy recursion)</li>
<li>Template Inheritance</li>
<li>PHP Streams Support (per template/variable/include)</li>
<li>Smart javascript/css handling (no more {literal} tags)</li>
<li>Improved Cache handling (per template/variable/function)</li>
<li>and much more..!</li>
</ul>
<p>Though as per my knowledge I have analyzed that <strong>Smarty 3.0</strong> don't bring much <em>speed</em> over <strong>Smarty 2.x</strong> series, but as we can see there are many other benefits/features worth upgrading to newer release.</p>
<p>You can try downloading it from <a title="Download Smarty" href="http://www.smarty.net/download.php" target="_blank">here</a>.</p>
<p><em>Please share your experience with Smarty or your favorite template engine with us here by posting them on comments section.</em><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/database/mysql/heidisql-40-rc1-released/" rel="bookmark" title="January 10, 2009">HeidiSQL 4.0 RC1 released</a></li>
<li><a href="http://blogs.digitss.com/news/netbeans-7-0-rc1-released/" rel="bookmark" title="April 4, 2011">Netbeans 7.0 RC1 Released</a></li>
<li><a href="http://blogs.digitss.com/php/when-php-frameworks-are-going-to-stop-php-4-support/" rel="bookmark" title="August 15, 2009">When PHP Frameworks are going to stop PHP 4 support?</a></li>
<li><a href="http://blogs.digitss.com/php/top-open-source-php-frameworks/" rel="bookmark" title="March 22, 2008">Top Open Source PHP Frameworks</a></li>
<li><a href="http://blogs.digitss.com/php/codeigniter-2-is-just-here-about-to-release/" rel="bookmark" title="November 5, 2010">CodeIgniter 2 is just here &#8211; about to release..!</a></li>
</ul>
<p><!-- Similar Posts took 7.389 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/smarty-3-0-is-almost-here/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Upgrading to PHP 5.3..! &#8211; are you sure?</title>
		<link>http://blogs.digitss.com/php/upgrading-to-php-5-3-are-you-sure/</link>
		<comments>http://blogs.digitss.com/php/upgrading-to-php-5-3-are-you-sure/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 15:28:06 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=305</guid>
		<description><![CDATA[If you are planning to upgrade to PHP 5.3 from PHP 5.2.x then you must think twice before you really do it. There are few things you should take care of. Recently last week I tried upgrading one of the web-server to PHP 5.3 from PHP 5.2.9 and it was not a good idea which I came to know later on.]]></description>
			<content:encoded><![CDATA[<p>If you are planning to upgrade to PHP 5.3 from PHP 5.2.x then you must think twice before you really do it. There are few things you should take care of. Recently last week I tried upgrading one of the web-server to PHP 5.3 from PHP 5.2.9 and it was not a good idea which I came to know later on.</p>
<p>It is not only about deprecated functions which are creating Warnings or Notices but <a title="TCPDF" href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf" target="_blank">TCPDF</a> library for generating PDF has created some wired problems due to which I have to roll back to the older version, as it was one of the crucial functionality of the application. It was not a planned version upgrade but it was a server migration and on the fly I tried upgrading PHP version also.</p>
<p>There are many functions and some of php.ini parameters which are deprecated, for complete list please refer <a href="http://www.php.net/manual/de/migration53.deprecated.php">http://www.php.net/manual/de/migration53.deprecated.php</a>.</p>
<p>You can’t pass parameter while overriding “<strong>magic methods</strong>”; so if you ever had your __toString() method overridden with __toString($device = ‘SCREEN’) then it won’t work with PHP5.3. Other than that date_default_timezone() or similar timezone setup function also had some problems.</p>
<pre class="php"><span style="color: #808080; font-style: italic;">// This won't work with PHP5.3 and will work with 5.x</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __tostring<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$device</span> = <span style="color: #ff0000;">&quot;SCREEN&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span> ... <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// This will work with PHP5.3 and 5.x</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __tostring<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span> ... <span style="color: #66cc66;">&#125;</span></pre>
<p>So crux is if your applications are not ready for PHP5.3 it is not wise decision to upgrade and if you have to upgrade we should make sure to test whole application and all functionalities as with large development teams sometimes you never know who has used what all the time.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/javascript/jquery-javascript/jquery-1-4-released-jquery-ui-has-yet-to-achieve-compatibility-with-it/" rel="bookmark" title="January 24, 2010">jQuery 1.4 Released &#8211; jQuery UI has yet to achieve compatibility with it&#8230;</a></li>
<li><a href="http://blogs.digitss.com/technology/hacking-jquery-thickbox/" rel="bookmark" title="April 27, 2008">Hacking jQuery Thickbox..!</a></li>
<li><a href="http://blogs.digitss.com/php/codeigniter-2-is-just-here-about-to-release/" rel="bookmark" title="November 5, 2010">CodeIgniter 2 is just here &#8211; about to release..!</a></li>
<li><a href="http://blogs.digitss.com/javascript/calculate-datetime-difference-simple-javascript-code-snippet/" rel="bookmark" title="April 4, 2010">Calculate Date/Time difference &#8211; Simple Javascript code snippet</a></li>
<li><a href="http://blogs.digitss.com/programming/printing-data-table-vertically-why-and-how/" rel="bookmark" title="January 3, 2011">Printing data table vertically..! Why? and How?</a></li>
</ul>
<p><!-- Similar Posts took 7.067 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/upgrading-to-php-5-3-are-you-sure/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using Zimbra LDAP Server Authentication with PHP</title>
		<link>http://blogs.digitss.com/php/using-zimbra-ldap-server-authentication-with-php/</link>
		<comments>http://blogs.digitss.com/php/using-zimbra-ldap-server-authentication-with-php/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 07:20:07 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[zimbra]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=297</guid>
		<description><![CDATA[I wanted to provide our CRM users an alternate way of logging to the system using their Zimbra email authentication and there is a really easy way of doing it which I have figured out in little while with googling. Definitely PHP online help docs and Zimbra forums both came to help and found a [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to provide our CRM users an alternate way of logging to the system using their Zimbra email authentication and there is a really easy way of doing it which I have figured out in little while with googling. Definitely PHP online help docs and Zimbra forums both came to help and found a correct options to use from Zimbra Forums which is powered by it's USERS.</p>
<p>Just make sure to enable <strong>php_ldap</strong> extension before you move further.</p>
<pre>// Uncomment following line from php.ini
extension=php_ldap.dll</pre>
<p>Following code snippet could be used to authenticate and find out whether provided Username and Password belongs to valid Zimbra User or not by authenticating it with Zimbra's LDAP (Light-weight Directory Access Protocol) server. So this way if you want you can provide your intranet/business application users an ability to use their Zimbra (mail/collaboration system) password to be used as an optional way to authenticate themselves.<span id="more-297"></span></p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// Domain to be authenticated when your zimbra mail server is setup like &quot;zimbra.domain.com&quot;</span>
<span style="color: #0000ff;">$Domain</span> = <span style="color: #ff0000;">'digitss'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Username to be authenticated</span>
<span style="color: #0000ff;">$Username</span> = <span style="color: #ff0000;">'guest'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Password; these username and password could be passed from login form</span>
<span style="color: #0000ff;">$Password</span> = <span style="color: #ff0000;">'password'</span>;
&nbsp;
<span style="color: #0000ff;">$IsValidUser</span> = <span style="color: #000000; font-weight: bold;">FALSE</span>;
&nbsp;
try
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// Just in case your Zimbra server is setup in a format like &quot;zimbra.domain.com&quot;</span>
	<span style="color: #0000ff;">$LDAPConnection</span>    =    ldap_connect<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;zimbra.&quot;</span>.<span style="color: #0000ff;">$Domain</span>.<span style="color: #ff0000;">&quot;.com&quot;</span>,<span style="color: #cc66cc;">389</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
catch<span style="color: #66cc66;">&#40;</span>Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$error</span> = <span style="color: #ff0000;">&quot;Can't connect to LDAP server.&quot;</span> . <span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">// Set LDAP protocol version to 3: not being able to set will cause an error and can't continue further</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!ldap_set_option<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$LDAPConnection</span>,LDAP_OPT_PROTOCOL_VERSION,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$error</span> = <span style="color: #ff0000;">&quot;LDAP Server protocol error.&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// Authenticate Username and Password using ldap_bind function</span>
try
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$LDAPbind</span>    =    @ldap_bind<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$LDAPConnection</span>,<span style="color: #ff0000;">'uid='</span>.<span style="color: #0000ff;">$Username</span>.<span style="color: #ff0000;">',ou=people,dc='</span>.<span style="color: #0000ff;">$Domain</span>.<span style="color: #ff0000;">',dc=com'</span> , <span style="color: #0000ff;">$Password</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$LDAPbind</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$IsValidUser</span> = <span style="color: #000000; font-weight: bold;">TRUE</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
catch<span style="color: #66cc66;">&#40;</span>Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$error</span> = <span style="color: #ff0000;">&quot;Unable to bind: &quot;</span> . <span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<p>Above code snippet can be molded as a function which could optionally authenticate and users with Zimbra or any other LDAP authentication with little modification.</p>
<p><strong>References:</strong></p>
<p>http://us2.php.net/manual/en/book.ldap.php</p>
<p>http://www.zimbra.com/forums/21931-post1.html</p>
<p>http://wiki.zimbra.com/index.php?title=LDAP_Authentication<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/software/zimbra-open-source-works-great/" rel="bookmark" title="January 26, 2009">Zimbra open-source works great..!</a></li>
<li><a href="http://blogs.digitss.com/tools-plugins-extenstion/penango-secure-encrypted-email-w-attachments/" rel="bookmark" title="February 20, 2011">Penango &#8211; secure encrypted email w/ attachments for Gmail, Google Apps and Zimbra</a></li>
<li><a href="http://blogs.digitss.com/php/reading-mssql-blog-column-data-with-php/" rel="bookmark" title="April 1, 2011">Reading MSSQL BLOG column data with PHP</a></li>
<li><a href="http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/" rel="bookmark" title="March 6, 2011">Posting or Uploading Files using cURL with PHP</a></li>
<li><a href="http://blogs.digitss.com/php/php-text-encoding-challenge/" rel="bookmark" title="January 26, 2009">PHP Text Encoding &#8211; Challenge..!</a></li>
</ul>
<p><!-- Similar Posts took 4.638 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/using-zimbra-ldap-server-authentication-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>When PHP Frameworks are going to stop PHP 4 support?</title>
		<link>http://blogs.digitss.com/php/when-php-frameworks-are-going-to-stop-php-4-support/</link>
		<comments>http://blogs.digitss.com/php/when-php-frameworks-are-going-to-stop-php-4-support/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 16:55:45 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Framework]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=289</guid>
		<description><![CDATA[As of now we have many frameworks which are still supporting PHP 4.x. CakePHP and CodeIgniter are leading that troop. Now we have PHP 6 about to get ready for production and PHP 5.x is in it's mature stage since long while now with PHP 5.3 as the latest release. I am not against for support on 4.x version of PHP; may great developers/teams have developed awasom tools and application and they should be still usable without any modifications in their coding.]]></description>
			<content:encoded><![CDATA[<p>As of now we have many frameworks which are still supporting PHP 4.x. <a href="http://www.cakephp.org" target="_blank">CakePHP</a> and <a href="http://www.codeigniter.com" target="_blank">CodeIgniter</a> are leading that troop. Now we have PHP 6 about to get ready for production and PHP 5.x is in it's mature stage since long while now with PHP 5.3 as the latest release. I am not against for support on 4.x version of PHP; may great developers/teams have developed awasom tools and application and they should be still usable without any modifications in their coding.</p>
<p><span style="text-decoration: underline;"><strong>PHP 4.x Hosting:</strong></span></p>
<p>So PHP 4.x support for hosting is fine and it's required to keep those applications running and being hosted without any maintenance saving efforts and time. So applications developed for PHP 4.x can run as long as they wish and till there are no equivalent forks of them available in PHP 5.x or newer version.</p>
<p><strong><span style="text-decoration: underline;">PHP 4.x for Development:</span></strong></p>
<p>PHP 4.4.9 has been released as final release for PHP 4.x now and it has been announced as <strong>end of life</strong> for PHP 4.x now. So developing any project or framework by keeping PHP 4.x compatibility is not a good idea I believe. All projects or framework has to freeze their PHP 4.x versions and let only bug-fixes be made available for those versions and have new feature-set addition be on the fork which is only PHP 5.x. I think every project will have to come up with a date when they will join GoPHP5 rally. For example <a title="Symfony Installation Guide" href="http://www.symfony-project.org/installation" target="_blank">Symfony 1.2 and 1.3</a> (<a title="Symfony About" href="http://www.symfony-project.org/about" target="_blank">Symfony</a> is a PHP 5 only MVC Framework) are specifically supporting PHP 5.2.4 or newer version only.</p>
<p>Basically for newer development it is better idea to use version which has longer future so that finally they don't need to write a fixes which allow those projects to continue working in both the environment. Which will save time on development, QA and maintanence all phases.</p>
<p>I am not against the PHP 4.x but it is a change which is eneviable and which has to happen in it's completeness sometime and change is for good. I am not sure how many of you agree with my thoughts but please share your thoughts on this subjects as comments for this post.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/php/top-open-source-php-frameworks/" rel="bookmark" title="March 22, 2008">Top Open Source PHP Frameworks</a></li>
<li><a href="http://blogs.digitss.com/php/symfony-12-first-beta-is-out/" rel="bookmark" title="November 6, 2008">Symfony 1.2 first Beta is out</a></li>
<li><a href="http://blogs.digitss.com/php/symfony-11-rc1-released/" rel="bookmark" title="May 10, 2008">Symfony 1.1 RC1 Released</a></li>
<li><a href="http://blogs.digitss.com/php/setting-up-php-mysql-apache-with-most-up-to-date-wamp-package/" rel="bookmark" title="January 17, 2011">Setting up PHP, MySQL, Apache with most up-to-date WAMP Package</a></li>
<li><a href="http://blogs.digitss.com/software/netbeans-6-8-is-out/" rel="bookmark" title="December 14, 2009">NetBeans 6.8 is out</a></li>
</ul>
<p><!-- Similar Posts took 1996.232 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/when-php-frameworks-are-going-to-stop-php-4-support/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP Text Encoding &#8211; Challenge..!</title>
		<link>http://blogs.digitss.com/php/php-text-encoding-challenge/</link>
		<comments>http://blogs.digitss.com/php/php-text-encoding-challenge/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 19:43:44 +0000</pubDate>
		<dc:creator>Dharmavirsinh Jhala</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[encoding]]></category>

		<guid isPermaLink="false">http://blogs.digitss.com/?p=183</guid>
		<description><![CDATA[I have faced some challenge in respect of text encoding with PHP in near past and would like to share with all of you. I am not sure that it indicates PHP's limitation/weakness in that particular area or just a blind spot for me..! But would like to know about that as for that particular instance I took help of small C# utility to get it done.]]></description>
			<content:encoded><![CDATA[<p>Before sometime I had a project where I am required to create a message digest to authenticate web-service call. Initially it looked simple but while trying on staging server it never authenticated properly. Basically it was a <a title="Surescripts - Rx HUB" href="http://www.surescripts.com/" target="_blank">Surescripts</a> web-service implementation where we have to strictly follow their protocols.<span id="more-183"></span></p>
<p>They have provided documentation to help implementing/developing compatible services but clarity was missing, we have to go forth and back to their staging (FASTRACK) support which was limited to email only in most of the case except for production you can get better support with phone agents. I mean it was bit tricky for first time Surescripts implementers.</p>
<p>OK, anyway let's get back to basics now, I have sample code in VB.NET and Java and I have to perform following operation: "<strong>The encoding process for password is: first convert to uppercase, then Unicode it in little-endian UTF16, then SHA1 it, then base64 encode it.</strong>"</p>
<p><span style="text-decoration: underline;">Sample VB.NET code:</span></p>
<pre class="vbnet">UnicodeEncoding encoding = <span style="color: #FF8000;">new</span> UnicodeEncoding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
hashBytes = encoding.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span>password.<span style="color: #0000FF;">ToUpper</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0600FF;">Trim</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
SHA1 sha1 = <span style="color: #FF8000;">new</span> SHA1CryptoServiceProvider<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> cryptPassword = sha1.<span style="color: #0000FF;">ComputeHash</span><span style="color: #000000;">&#40;</span>hashBytes<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #FF8000;">String</span> pwd= Convert.<span style="color: #0000FF;">ToBase64String</span><span style="color: #000000;">&#40;</span>cryptPassword<span style="color: #000000;">&#41;</span>;</pre>
<p>and here is, <span style="text-decoration: underline;"><br />
Sample Java code:</span></p>
<pre class="java"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> <span style="color: #66cc66;">&#40;</span>
<span style="color: #000000; font-weight: bold;">new</span> Base64<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AMessageDigest+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">MessageDigest</span></a>.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SHA1&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">digest</span><span style="color: #66cc66;">&#40;</span>pwString.<span style="color: #006600;">getBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;UTF-16LE&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p><!--adsense--><br />
But, luckily or unluckily there was no PHP sample code which used to be the case many a times for such projects. I don't mind that and while I already worked real hard on rest of the part I have just developed a small simple one page VB.NET application/web-page which I could call from my PHP application to get the message digest in the desired way.</p>
<p>So I got my solution there at that time as always; may be in unconventional way but I don't mind as long as I can deliver acceptable solution in-time. But I would like some of the great PHP experts to digg into this matter and bring solution to the horizon. I believe some of the things in respect of text encoding are not much clear as I have tried lot to get this done in PHP itself and have spent good amount of time on that research as well. Tried using all sort of various encoding functions available in PHP including <a title="PHP - mbstring" href="http://in.php.net/mbstring" target="_blank">mbstring</a>.</p>
<p>According to their code and samples for string "<span style="text-decoration: underline;"><strong>helloworld</strong></span>" the output should be "<span style="text-decoration: underline;"><strong>D3Kwlpztzu5ZimQFg916lDn8/rQ=</strong></span>"; and yes it works really well without any headache (I tried <strong>VB.NET</strong> code and it worked for me right out of the box and <strong>C# </strong>conversion of that code worked as well). I know that Surescripts guys have build their backbone on .NET platform but such things should not matter here.</p>
<p>I would like to know  "how?"; if we can get it done with the help of <strong>PHP</strong>. I believe in <strong>PHP </strong>and it's strength and that's why posting this on my blog hoping to see positive response <img src='http://blogs.digitss.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>PS: Here skySignal has something similar to say about <a title="Porting the Equivalent of PHP’s MD5 to .NET platform in C#" href="http://skysigal.xact-solutions.com/Blog/tabid/427/EntryId/425/Porting-the-Equivalent-of-PHP-rsquo-s-MD5-to-NET-platform-in-C.aspx" target="_blank">MD5 usage and implementation in PHP in respect to Microsoft.NET</a>.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://blogs.digitss.com/database/mysql/mysql-5-5-8-problem-while-creating-new-user-sql-error-1364-field-authentication_string-doesnt-have-a-default-value/" rel="bookmark" title="January 16, 2011">MySQL 5.5.8 &#8211; Problem while Creating new User (SQL Error (1364): Field &#8216;authentication_string&#8217; doesn&#8217;t have a default value)</a></li>
<li><a href="http://blogs.digitss.com/php/php-performance-improvement-tips/" rel="bookmark" title="August 9, 2008">PHP: Performance Improvement Tips</a></li>
<li><a href="http://blogs.digitss.com/tools-plugins-extenstion/use-google-docs-viewer-for-document-viewing-within-browser/" rel="bookmark" title="January 24, 2010">Use Google Docs Viewer for Document viewing within Browser</a></li>
<li><a href="http://blogs.digitss.com/programming/printing-data-table-vertically-why-and-how/" rel="bookmark" title="January 3, 2011">Printing data table vertically..! Why? and How?</a></li>
<li><a href="http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/" rel="bookmark" title="March 6, 2011">Posting or Uploading Files using cURL with PHP</a></li>
</ul>
<p><!-- Similar Posts took 317.505 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.digitss.com/php/php-text-encoding-challenge/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 14.356 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2011-08-20 00:29:11 -->

