<?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>Three2Tango &#187; PHP</title>
	<atom:link href="http://www.three2tango.com/category/techcorner/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.three2tango.com</link>
	<description>Points To Ponder : The Latest news from the TechWorld,Automobiles,CellPhones and lots of useful Code Snippets</description>
	<lastBuildDate>Fri, 27 Jan 2012 09:03:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Building a Login Form using PHP/MySQL</title>
		<link>http://www.three2tango.com/techcorner/building-a-login-form-using-phpmysql.html/</link>
		<comments>http://www.three2tango.com/techcorner/building-a-login-form-using-phpmysql.html/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 13:35:06 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[Login form using PHP/MySQL]]></category>
		<category><![CDATA[PHP/MySQL]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2386</guid>
		<description><![CDATA[This tutorial shows you how to build a simple login form and to check the login credentials entered against te database using PHP and MySQL.I had introduced some PHP lessons earlier.It might be worth to take a look at them before you go through this.Anyway,this isnt any harder.I have specially included this as an article because a login form is an essential component of most dynamic websites.
Again we are using MySQL database.Create a database(here i have created one called as &#8220;test&#8221;).Now create a table &#8216;login&#8217; with two fields namely &#8216;username&#8217; and &#8216;password&#8217;.Make &#8216;username&#8217; the ...]]></description>
			<content:encoded><![CDATA[<p>This tutorial shows you how to build a simple login form and to check the login credentials entered against te database using PHP and MySQL.I had introduced some <a href="http://www.three2tango.com/category/techcorner/php/" target="_blank">PHP lessons</a> earlier.It might be worth to take a look at them before you go through this.Anyway,this isnt any harder.I have specially included this as an article because a login form is an essential component of most dynamic websites.</p>
<p>Again we are using MySQL database.Create a database(here i have created one called as &#8220;test&#8221;).Now create a table &#8216;login&#8217; with two fields namely &#8216;username&#8217; and &#8216;password&#8217;.Make &#8216;username&#8217; the primary key as we do not want the same username to be used more than once.</p>
<blockquote><p>CREATE TABLE `test`.`login1` (<br />
`username` VARCHAR( 30 ) NOT NULL ,<br />
`password` VARCHAR( 30 ) NOT NULL ,<br />
PRIMARY KEY ( `username` )<br />
)</p></blockquote>
<p>Now all that is needed is a login form and some PHP code to read the values entered in the textboxes and to verify them against the values in the database. Here is the code of <em>login.php</em>:<br />
<script type="text/javascript"><!--
google_ad_client = "pub-6525089797582043";
/* 468x15, created 7/8/09 */
google_ad_slot = "8684679217";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<code>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;<br />
&lt;h2&gt;Login Form&lt;/h2&gt;<br />
&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php<br />
//display the form if it has not been submitted yet<br />
if(!isset($_POST['submit'])){<br />
?&gt;<br />
&lt;form method="post" action="login.php"&gt;<br />
Username:&lt;input type="text" name="username"/&gt;&lt;/br&gt;<br />
Password:&lt;input type="password" name="password"/&gt;&lt;/br&gt;<br />
&lt;input type="submit" name="submit" value="Login"/&gt;<br />
&lt;/form&gt;<br />
&lt;?php<br />
//if the form has been submitted,check entered values against the database<br />
}<br />
else<br />
{<br />
$username=$_POST['username'];<br />
$password=$_POST['password'];<br />
//attempt the database connection<br />
$mycon=mysql_connect("localhost","root","");<br />
if(!$mycon)<br />
{die('Could not connect'.mysql_error());}</code></p>
<p><code> </code></p>
<p><code>mysql_select_db("test",$mycon);<br />
$result=mysql_query("select * from login where username='$username' and password='$password'");<br />
$num=mysql_numrows($result);<br />
if($num==0)<br />
{<br />
echo "Incorrect Login Details";<br />
}<br />
else<br />
{<br />
echo "Login Sucessful";<br />
}<br />
mysql_close($mycon);<br />
}<br />
?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p><span style="color: #ff6600;"><a href="http://www.three2tango.com/ourfiles/login.zip">Download the entire code</a></span></p>
<p>The below fig illustrates how the form will look like.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/08/loginform.JPG"><img class="aligncenter size-medium wp-image-2387" title="loginform" src="http://www.three2tango.com/wp-content/uploads/2009/08/loginform-300x225.jpg" alt="loginform" width="300" height="225" /></a></p>
<p>Here when the form is submitted,the secnd half of the script comes into play.First,we save the entered values into two variables and then run the query &#8220;select * from login where username=&#8217;$username&#8217; and password=&#8217;$password&#8217;&#8221;. Now the idea behind this is that if there is a row satisfying the above query,the number of rows returned will be more than zero.Also,we only need to check if the number of rows is more than zero since the username is a primay key and hence there can be only one row that can satisfy the above query.</p>
<p>The $num=mysql_numrows($result); code will assign the number of rows to the $num variable.All we have to check now is whether the variable is zero or not.If it is zero,then the login credentials submitted are incorrect else you have submitted the right username and password.</p>
<p>Finally dont forget to close the connection.Even though it will not generate an error in the above case,it is always a good practice to close the connection to keep the server running well.</p>
<p>The above form is a very simple login form.However,we will be using encrypted passwords in most cases.In that case,before running the query,encrypt the entered password using the same encryption technique used when the values were submitted to the database.To learn more about encryption in PHP,<a href="http://www.three2tango.com/techcorner/data-encryption-in-php-using-crypt.html/">follow this link</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/building-a-login-form-using-phpmysql.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The History of PHP</title>
		<link>http://www.three2tango.com/techcorner/the-history-of-php.html/</link>
		<comments>http://www.three2tango.com/techcorner/the-history-of-php.html/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 21:09:10 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[PHP History]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2346</guid>
		<description><![CDATA[PHP in little over 14 years have become one of the most popular prgramming language for web development.PHP or Hypertext Preprocessor&#8217;s have become popular on account of its ease of use,scalability and wide spread support for various databases and data formats.Another aspect of its ever growing popularity is that it is open source and hence freely available on the internet.These are the main reasons why PHP is used in over 30 million websites and more than one third of the web servers.
The earliest version of PHP,codenamed as PHP/FI was a ...]]></description>
			<content:encoded><![CDATA[<p>PHP in little over 14 years have become one of the most popular prgramming language for web development.PHP or Hypertext Preprocessor&#8217;s have become popular on account of its ease of use,scalability and wide spread support for various databases and data formats.Another aspect of its ever growing popularity is that it is open source and hence freely available on the internet.These are the main reasons why PHP is used in over 30 million websites and more than one third of the web servers.</p>
<p>The earliest version of PHP,codenamed as PHP/FI was a fairly primitive language with support for form input and mSQL  database.It lacked the security features and other features of today&#8217;s available versions.It constituted of Perl like variables,automatic interpretation of form variables and HTML embedded syntax.The first improvement to the basic language came from developer Rasmus Lerdorf,(who actually created PHP/FI),who improved the PHP/FI and released the PHP/FI 2.0.</p>
<p>In 1997,developers Andi Gutmans and  Zeev Suraski rewrote the PHP syntax to form the PHP/FI 3.0 and the popularity of the language began to rise.More and more people participated in the enrichment of the language as the project was open sourced.The PHP/FI 3.0&#8242;s syntax was more powerful and consistent and allowed independent developers to create their own add ons and extensions.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-6525089797582043";
/* 468x15, created 7/8/09 */
google_ad_slot = "8684679217";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
The next version PHP 4.0 was released in 2000 boasted an improved object model and various security and performance improvements.OOP concepts were now being supported by PHP and this made programming a lot easier and hence the popularity of the open sourced language rose even further.Abstract classes,constructors,destructors and other OOP concepts became available to use.The new engine called as &#8216;ZEND&#8217;(ZEev and ANdi) made it possible to improve the performance of complex applications.</p>
<p>PHP 5.0 introduced exception handling,data access layer and an integrated database engine to further enhance the already feature-rich language.The PHP 5.0 engine(Zend Engine 2.0) also came with an optimized memory manager which improved the performance of the language in terms of speed of execution.The newest versions now supports namespaces an built in support for SQLite 3.0 and much more.</p>
<p>Well all these features have prompted developers to use PHP on their websites and hence PHP is now used in almost 30 million websites.Feature rich(now with over 5000 built in functions) yet free of cost.What more would you want?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/the-history-of-php.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Simple Image Gallery using PHP</title>
		<link>http://www.three2tango.com/techcorner/creating-a-simple-image-gallery-using-php.html/</link>
		<comments>http://www.three2tango.com/techcorner/creating-a-simple-image-gallery-using-php.html/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 07:02:38 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[Image gallery using PHP]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2247</guid>
		<description><![CDATA[Here i will show how to make an image gallery using PHP&#8217;s File Manipulation functions.The code  basically generates a web page to display image by scanning a specified directory.
For this first we need to define the location of the images.This directory should be accessible by  the script owner,meaning you should have read permissions on the directory.The directory can be  defined as follows:
$photosDir = &#8216;./photos&#8217;;
If you are using Wamp server,create the folder &#8216;photos&#8217; inside the &#8216;www&#8217; root folder for the above code to work.Now set up an array ...]]></description>
			<content:encoded><![CDATA[<p>Here i will show how to make an image gallery using PHP&#8217;s File Manipulation functions.The code  basically generates a web page to display image by scanning a specified directory.</p>
<p>For this first we need to define the location of the images.This directory should be accessible by  the script owner,meaning you should have read permissions on the directory.The directory can be  defined as follows:</p>
<blockquote><p>$photosDir = &#8216;./photos&#8217;;</p></blockquote>
<p>If you are using Wamp server,create the folder &#8216;photos&#8217; inside the &#8216;www&#8217; root folder for the above code to work.Now set up an array containing the common file extensions for the images.<br />
Initialize an array to read the directory contents and then build the photo list.</p>
<p>To open the directory,we use the <strong>opendir()</strong> function.The opendir() function takes the above formed variable $photosDir,that is the variable containing the location of the images.The openDir() returns a pointer to the directory named as the parameter.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-6525089797582043";
/* 234x60, created 8/6/09 */
google_ad_slot = "5659436479";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
Now using the above pointer,we iterate over the directory using the <strong>readdir()</strong> function,which returns a single entry each time.Once done,use the <strong>closedir()</strong> funcion to close the file pointer.</p>
<blockquote><p>if (file_exists($photosDir)) {<br />
$dp = opendir($photosDir) or die (&#8216;ERROR: Cannot open directory&#8217;);<br />
while ($file = readdir($dp)) {<br />
if ($file != &#8216;.&#8217; &amp;&amp; $file != &#8216;..&#8217;) {<br />
$fileData = pathinfo($file);<br />
if (in_array($fileData['extension'], $photosExt)) {<br />
$photosList[] = &#8220;$photosDir/$file&#8221;;<br />
}<br />
}<br />
}<br />
closedir($dp);</p></blockquote>
<p>Now iterate through the above formed array-photoList[] and display each image.For that, run a &#8216;for&#8217; loop and define the img src in each case:</p>
<blockquote><p>&lt;img height=&#8221;150&#8243; width=&#8221;200&#8243;<br />
src=&#8221;&lt;?php echo $photosList[$x]; ?&gt;&#8221; /&gt;</p></blockquote>
<p>Here is the screen shot of what you will achieve.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/08/imagegallery.JPG"><img class="aligncenter size-medium wp-image-2248" title="imagegallery" src="http://www.three2tango.com/wp-content/uploads/2009/08/imagegallery-300x200.jpg" alt="imagegallery" width="300" height="200" /></a></p>
<p>Here is the entire code.</p>
<blockquote><p><code>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Creating An Image Gallery&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;style type="text/css"&gt;<br />
ul {<br />
list-style-type: none;<br />
}<br />
li {<br />
float: left;<br />
padding: 10px;<br />
margin: 10px;<br />
font: bold 10px Verdana, sans-serif;<br />
}<br />
img {<br />
display: block;<br />
border: 1px solid #333300;<br />
margin-bottom: 5px;<br />
}<br />
&lt;/style&gt;<br />
&lt;body&gt;<br />
&lt;h2&gt;Creating An Image Gallery&lt;/h2&gt;<br />
&lt;ul&gt;<br />
&lt;?php<br />
// define location of photo images<br />
$photosDir = './photos';<br />
// set up an array of known extensions<br />
$photosExt = array('gif', 'jpg', 'jpeg', 'tif', 'tiff', 'bmp', 'png');<br />
// initialize array to hold filenames of images found<br />
$photosList = array();<br />
// read directory contents and // build photo list<br />
if (file_exists($photosDir)) {<br />
$dp = opendir($photosDir) or die ('ERROR: Cannot open directory');<br />
while ($file = readdir($dp)) {<br />
if ($file != '.' &amp;&amp; $file != '..') {<br />
$fileData = pathinfo($file);<br />
if (in_array($fileData['extension'], $photosExt)) {<br />
$photosList[] = "$photosDir/$file";<br />
}<br />
}<br />
}<br />
closedir($dp);<br />
} else {<br />
die ('ERROR: Directory does not exist.');<br />
}<br />
// iterate over photo list and display each image<br />
if (count($photosList) &gt; 0) {<br />
for ($x=0; $x&lt;count($photosList); $x++) {<br />
?&gt;<br />
&lt;li&gt;<br />
&lt;img height="150" width="200"<br />
src="&lt;?php echo $photosList[$x]; ?&gt;" /&gt;<br />
&lt;/li&gt;<br />
&lt;?php<br />
}<br />
} else {<br />
die('ERROR: No images found in directory');<br />
}<br />
?&gt;<br />
&lt;/ul&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p></blockquote>
<p><a href="ftp://ftp.three2tango.com/www.three2tango.com/Files1/gallery.zip">Download the full code</a><br />
<span style="color: #ff0000;">Note:Don&#8217;t forget to change the path of the directory containing the images</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/creating-a-simple-image-gallery-using-php.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Forms</title>
		<link>http://www.three2tango.com/techcorner/php-forms.html/</link>
		<comments>http://www.three2tango.com/techcorner/php-forms.html/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 09:04:05 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[$_GET and $_POST]]></category>
		<category><![CDATA[PHP Forms]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2218</guid>
		<description><![CDATA[As you would have noticed in the earlier posts,the $_GET and $_POST variables are used to retrieve information from a web form.All HTML form elements are automatically available to the PHP script.Lets see how the form elements are made available to the PHP script.
&#60;html&#62;
&#60;body&#62;
&#60;form action=&#8221;welcome.php&#8221; method=&#8221;post&#8221;&#62;
Name: &#60;input type=&#8221;text&#8221; name=&#8221;username&#8221; /&#62;
&#60;input type=&#8221;submit&#8221; /&#62;
&#60;/form&#62;
&#60;/body&#62;
&#60;/html&#62;
Now when the submit button is clicked,the &#8220;welcome.php&#8221; script is called,which looks something like this
&#60;html&#62;
&#60;body&#62;
Welcome &#60;?php echo $_POST["username"]; ?&#62;!
&#60;/body&#62;
&#60;/html&#62;
The above form passes values using the &#8220;post&#8221; method and hence the $_POST function is used to retrieve the form data.
The ...]]></description>
			<content:encoded><![CDATA[<p>As you would have noticed in the earlier posts,the $_GET and $_POST variables are used to retrieve information from a web form.All HTML form elements are automatically available to the PHP script.Lets see how the form elements are made available to the PHP script.</p>
<blockquote><p><code>&lt;html&gt;<br />
&lt;body&gt;</code></p>
<p>&lt;form action=&#8221;welcome.php&#8221; method=&#8221;post&#8221;&gt;<br />
Name: &lt;input type=&#8221;text&#8221; name=&#8221;username&#8221; /&gt;<br />
&lt;input type=&#8221;submit&#8221; /&gt;<br />
&lt;/form&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>Now when the submit button is clicked,the &#8220;welcome.php&#8221; script is called,which looks something like this</p>
<blockquote><p><code>&lt;html&gt;<br />
&lt;body&gt;</code></p>
<p>Welcome &lt;?php echo $_POST["username"]; ?&gt;!</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>The above form passes values using the &#8220;post&#8221; method and hence the $_POST function is used to retrieve the form data.</p>
<p>The $_GET environment variable is used to retrieve data from forms with the &#8220;get&#8221; method.The main difference between the $_GET and $_POST is that the information that is passed from the form is visible to everyone,(it will be visible in the browser) and also there is a space limitation on the amount of information that can be send.</p>
<p>Lets see the above example using the $_GET function</p>
<blockquote><p><code>&lt;html&gt;<br />
&lt;body&gt;</code></p>
<p>&lt;form action=&#8221;welcome.php&#8221; method=&#8221;get&#8221;&gt;<br />
Name: &lt;input type=&#8221;text&#8221; name=&#8221;username&#8221; /&gt;<br />
&lt;input type=&#8221;submit&#8221; /&gt;<br />
&lt;/form&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>Here to retrieve the value,we use the $_GET function in the  welcome.php script</p>
<blockquote><p><code>&lt;html&gt;<br />
&lt;body&gt;</code></p>
<p>Welcome &lt;?php echo $_GET["username"]; ?&gt;!</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6525089797582043";
/* 468x15, created 7/8/09 */
google_ad_slot = "8684679217";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>The difference between the $_GET and $_POST functions can be noticed in the URLs of the two.</p>
<div id="attachment_2219" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.three2tango.com/wp-content/uploads/2009/08/addressbarwithget.JPG"><img class="size-medium wp-image-2219" title="addressbarwithget" src="http://www.three2tango.com/wp-content/uploads/2009/08/addressbarwithget-300x22.jpg" alt="URL using get" width="300" height="22" /></a><p class="wp-caption-text">URL using get</p></div>
<div id="attachment_2220" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.three2tango.com/wp-content/uploads/2009/08/addressbarwithpost.JPG"><img class="size-medium wp-image-2220" title="addressbarwithpost" src="http://www.three2tango.com/wp-content/uploads/2009/08/addressbarwithpost-300x22.jpg" alt="URL using post" width="300" height="22" /></a><p class="wp-caption-text">URL using post</p></div>
<p>As such,we should not use the $_GET function to pass sensitive data like password or credit card numbers.Also the amount of information that can be passed should not exceed 1024 characters.The variables are displayed in the URL and hence $_GET allows bookmarking of the web pages.Also,we cannot send binary data like images to the web server using get method.</p>
<p>When using $_POST,there is no limit in the amount of information that can be passed and also the data is invisible.But,since the variables are not available with the URL,we cannot bookmark the web page.</p>
<p>The $_REQUEST function can be used to collect information sent with both get or post methods.</p>
<blockquote><p><code>&lt;html&gt;<br />
&lt;body&gt;</code></p>
<p>Welcome &lt;?php echo $_REQUEST["username"]; ?&gt;!</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/php-forms.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Date/Time Functions</title>
		<link>http://www.three2tango.com/techcorner/php-datetime-functions.html/</link>
		<comments>http://www.three2tango.com/techcorner/php-datetime-functions.html/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 16:23:26 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[PHP Time Functions]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=1479</guid>
		<description><![CDATA[The time() and date() functions are the most used date/time functions in PHP.The time() function returns the current time as a unix timestamp.The date function can be then used to format this value to be human friendly.This is shown in the below example.
$CurrentTime=time();
echo(date("F d Y",$CurrentTime));
?&#62;
Output: January 1 2009
Another time function used is mktime().It is similar to the time() function except that it outputs a specified date and time and not the current time.In effect it artificially generates a timestamp based on inputed date and time.
The format for mktime() is
mktime ( ...]]></description>
			<content:encoded><![CDATA[<p>The <strong>time()</strong> and <strong>date()</strong> functions are the most used date/time functions in PHP.The time() function returns the current time as a unix timestamp.The date function can be then used to format this value to be human friendly.This is shown in the below example.</p>
<p><code><!--p<br-->$CurrentTime=time();<br />
echo(date("F d Y",$CurrentTime));<br />
?&gt;</code></p>
<p>Output: January 1 2009</p>
<p>Another time function used is <strong>mktime()</strong>.It is similar to the time() function except that it outputs a specified date and time and not the current time.In effect it artificially generates a timestamp based on inputed date and time.<br />
The format for mktime() is</p>
<p><strong>mktime ( hour, minute, second, month, day, year, is_dst)</strong>.</p>
<p>hour: Specifies the hour<br />
minute:Specifies the minute<br />
second : Specifies the second<br />
month :Specifies the month<br />
day: Specifies the day<br />
year: Specifies the year<br />
is_dst: =1 if the time is during daylight savings time (DST),<br />
=0 if it is not,<br />
=-1 default value if DST is unknown</p>
<p><code><!--p<br-->&lt;?php </code><code>echo(date("M-d-Y",mktime(0,0,0,12,32,2008)));<br />
?&gt; </code></p>
<p>The output is: Jan-1-2009</p>
<p>The <strong>date() </strong>function formats the date into a human readable format.<br />
The syntax for the date() function is<br />
<strong>date(format,timestamp);</strong><br />
The format parameter is used to specify the format in which you want to see the date.<br />
The timestamp is optional.The current timestamp is taken if this parameter is not passed.</p>
<p>The format is specified by using different letters.Some of the widely used letters are<br />
d-the day of the month in numeric<br />
m-Month in numeric<br />
Y-4 digit Year representation</p>
<p><code>&lt;?php<br />
 echo date("Y-m-d");<br />
 echo date("D M d, Y");<br />
?&gt;</code></p>
<p>Output:<br />
2009-06-17<br />
Wed Jun 17,2009</p>
<p>Using the timestamp parameter,we can find dates either using the <strong>strtotime</strong>() function or the <strong>mktime</strong>() function.An example for this is if we want to find yesterday&#8217;s date using today&#8217;s date.</p>
<p><code><?php<br />
echo "Yesterday's Date: ".date("Y-m-d", strtotime("-1 days"));<br />
?></code></p>
<p>Output: 2009-06-16</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/php-datetime-functions.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Manipulation in PHP</title>
		<link>http://www.three2tango.com/techcorner/file-manipulation-in-php.html/</link>
		<comments>http://www.three2tango.com/techcorner/file-manipulation-in-php.html/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 12:47:44 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[File operations in PHP]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=1379</guid>
		<description><![CDATA[PHP provides you with a great deal of tools for creating,reading and editing files.
This section deals with the various types of manipulations possible using PHP.
For any operations to be performed,we need a file.Lets first create a file.
In PHP,a file is created using the fopen() function.It may seem odd,but i can clarify that.
When fopen() is called,it will check whether a filename(that was given as argument to fopen()) exists or not.If the file does not exist,it will create the file.
fopen() takes two arguments,the name of the file and the access mode(whether you ...]]></description>
			<content:encoded><![CDATA[<p>PHP provides you with a great deal of tools for creating,reading and editing files.<br />
This section deals with the various types of manipulations possible using PHP.</p>
<p>For any operations to be performed,we need a file.Lets first create a file.<br />
In PHP,a file is created using the fopen() function.It may seem odd,but i can clarify that.<br />
When fopen() is called,it will check whether a filename(that was given as argument to fopen()) exists or not.If the file does not exist,it will create the file.<br />
fopen() takes two arguments,the name of the file and the access mode(whether you are opening the file for reading,writing or appending)<br />
In order to create the file,we should specify the access mode as &#8220;w&#8221; which stands for write.</p>
<p><img class="aligncenter size-full wp-image-1380" title="createfile" src="http://www.three2tango.com/wp-content/uploads/2009/06/createfile.bmp" alt="createfile" /></p>
<p><span style="color: #ff9900;"><a href="http://www.three2tango.com/Files1/createfile.zip" target="_blank">Download File Creation Code</a></span></p>
<p>When fopen() is called,the function returns a handle,which is used for further manipulations on the file.<br />
Now that we have created a file &#8220;test.txt&#8221;,lets do some operations on the same.</p>
<p>In the above code,we created test.txt using the fopen() function.Now lets use the fopen() to do some manipulations.</p>
<p>There are mainly three ways in which the file can be opened</p>
<p>The read mode,<br />
The write mode and the<br />
The append mode</p>
<p><strong>The read mode</strong><br />
The read mode is specified using &#8216;r&#8217; and the file is opened just for reading<br />
<strong> the write mode</strong><br />
The write mode is specified using &#8216;w&#8217;.Here you should be careful.When &#8216;w&#8217; is used,all the contents of the file are erased and the data will be written from the beginning of the file.<br />
<strong> The append mode</strong><br />
The append mode is specified using &#8216;a&#8217;.Here the file pointer begins from the end of the file and hence we need not fear that the contents may be erased.</p>
<p>But,these are not the only access modes available.The file can also be opened in such a way that both reading and writing is allowed.For that we place a + sign after the file mode character.</p>
<p><strong>Read/Write-&#8217;r+&#8217;</strong><br />
Here the file pointer is at the beginning of the file.<br />
<strong> write/read-&#8217;w+&#8217;</strong><br />
It is like the r+,but it deletes all the contents of the file first.<br />
<strong> Append-&#8217;a+&#8217;</strong><br />
The file pointer is at the end of the file.</p>
<p>fclose() should be called to free up the resources,even though the server will close all the files when the php code finishes execution.</p>
<p>Now,lets see how we can write to a file.To write to a file,the fwrite() function is used.First we need to open the file in write mode.fwrite() also takes two arguments,the file handle and the data to be written.So lets write some data into test.txt.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/06/writefile.bmp"><img class="aligncenter size-full wp-image-1382" title="writefile" src="http://www.three2tango.com/wp-content/uploads/2009/06/writefile.bmp" alt="writefile" /></a></p>
<p><a href="http://www.three2tango.com/Files1/writetofle.zip" target="_blank">Download File Write Code</a></p>
<p>Note that if at all a test.txt file exists,the contents in the file is over written by &#8220;three2tango.com&#8221;.<br />
If you want to add data into a file,you need to open the file in append mode instead of the write mode.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/06/appendfile.bmp"><img class="aligncenter size-full wp-image-1384" title="appendfile" src="http://www.three2tango.com/wp-content/uploads/2009/06/appendfile.bmp" alt="appendfile" /></a></p>
<p><a href="http://www.three2tango.com/Files1/appendtofile.zip" target="_blank">Download append to file Code</a></p>
<p>Here the contents are not over written.Instead the data &#8220;three2tango.com&#8221; is appended to the end of file.</p>
<p>Now,lets see how we can read from a file.<br />
To read information from a file,the fread() is used.<br />
For reading the file,the file should be opened in read mode.<br />
fread() also takes two arguments,the fle handle and an integer value.The integer tells the function how much data is to be read.So if you want to read 10 characters from the file,you will have to specify the integer as 10(1 character=1 byte)</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/06/readfile.bmp"><img class="aligncenter size-full wp-image-1386" title="readfile" src="http://www.three2tango.com/wp-content/uploads/2009/06/readfile.bmp" alt="readfile" /></a></p>
<p><a href="http://www.three2tango.com/Files1/readfile.zip" target="_blank">Download File read Code</a></p>
<p>To read the entire contents,you need to know the file size.For this,specify as the second argument,the filesize.The filesize() function can be used for this purpose.<br />
<a href="http://www.three2tango.com/wp-content/uploads/2009/06/readfullfile.bmp"><img class="aligncenter size-full wp-image-1388" title="readfullfile" src="http://www.three2tango.com/wp-content/uploads/2009/06/readfullfile.bmp" alt="readfullfile" /></a></p>
<p><a href="http://www.three2tango.com/Files1/readwholefile.zip" target="_blank">Download code to read entire file</a></p>
<p>In addition,for reading line by line,the fgets() function can be used.This takes the filehandle as the argument.<br />
Syntax:fgets($fileHandle);</p>
<p>Finally,lets see how we can delete a file.For deleting a file,the unlink() function is used.Make sure that you close the file before unlinking.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/06/fileunlink.bmp"><img class="aligncenter size-full wp-image-1389" title="fileunlink" src="http://www.three2tango.com/wp-content/uploads/2009/06/fileunlink.bmp" alt="fileunlink" /></a></p>
<p><a href="http://www.three2tango.com/Files1/deletefile.zip" target="_blank">Download File deletion Code</a></p>
<p>Note:Be careful when you do operations on files.You may end up editing the wrong file,accidentally deleting a file&#8217;s contents or filling garbage values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/file-manipulation-in-php.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cookies and Sessions in PHP</title>
		<link>http://www.three2tango.com/techcorner/cookies-and-sessions-in-php.html/</link>
		<comments>http://www.three2tango.com/techcorner/cookies-and-sessions-in-php.html/#comments</comments>
		<pubDate>Mon, 25 May 2009 14:14:43 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[session and cookies]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=1120</guid>
		<description><![CDATA[This post covers the basics in setting cookies and sessions in PHP.A Cookie is basically a message given by the web  server to the web browser.This message is stored in a text file and the message is sent back to the server every time the browser requests a page from the web server.The main purpose is to identify the users.The difference between a session and a cookie is that a cookie is set in the user's browser while the session is stored on the web server for later use.The web server cannot retrieve your information because the HTTP address does not maintain state.The scope of the session is between the time you enter the website and the time you leave the website.]]></description>
			<content:encoded><![CDATA[<p><strong>Cookie:</strong></p>
<p>A Cookie is basically a message given by the web  server to the web browser.This message is stored in a text file and the message is sent back to the server every time the browser requests a page from the web server.The main purpose is to identify the users.Here we will see how to set and retrieve values from a cookie in PHP.<br />
In PHP, a cookie is set using the setcookie() function.</p>
<blockquote><p>Syntax: setcookie(cookiename,value,expiration);</p></blockquote>
<p>Lets see a simple example to set a cookie.</p>
<p><code>&lt;?php<br />
setcookie("username","vivek",time()+2592000);<br />
?&gt;<br />
&lt;html&gt;<br />
....<br />
&lt;/html&gt;</code></p>
<p>In the above example a cookie named &#8220;username&#8221; is created with value &#8220;vivek&#8221;.The Cookie expires in 30 days.<br />
The setcookie() function url encodes the value so that it can be safely transmitted over the internet.url encoding converts the character to a format consisting of a % symbol followed by a 2 digit hexadecimal number.<br />
Note that the cookie is set before the html tag.</p>
<p>You can also use the setrawcookie() function if the information to be transmitted is not so important.setrawcookie() does not url encode the cookie value.</p>
<p>Having set the cookie,lets see how we can retrieve the cookie.When the cookie was set using setcookie(),the value was url encoded and send.When retrieved,this value is automatically decoded.<br />
To retrive the cookie value,the $COOKIE variable is used.<br />
Lets retrieve the cookie we just created above.</p>
<p><code>&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;?php<br />
if(isset($_COOKIE["username"]))<br />
echo "Welcome back to three2tango.com". $_COOKIE("username");<br />
else<br />
echo "Welcome to three2tango.com";<br />
?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>The isset() function checks whether the cookie exists.</p>
<p>To destroy a cookie,simply use setcookie() again with the expiration time set to the past.</p>
<p><code>&lt;?php<br />
setcookie("username","",time()-3600);<br />
?&gt;</code></p>
<p>The setcookie() function can be used only for browsers that supports cookies.</p>
<p><strong>Sessions:</strong></p>
<p>The difference between a session and a cookie is that a cookie is set in the user&#8217;s browser while the session is stored on the web server for later use.A common use is when you start an application and close it.The web server cannot retrieve your information because the HTTP address does not maintain state.The scope of the session is between<br />
the time you enter the website and the time you leave the website.In effect, a  session stores information of a session the website.</p>
<p>The session_start() function is used to start up the session. Like the setcokie(),the session_start() function should be placed before the html tag.<br />
So,lets see how to start a session</p>
<p><code>&lt;?php<br />
session_start();<br />
$_SESSION['username']=$_POST[username];<br />
?&gt;<br />
&lt;html&gt;<br />
...<br />
&lt;/html&gt;</code></p>
<p>This page accepts data from another page and sets the username as the session variable which will now be available throughout the application.<br />
A session can be destroyed using the unset() or the session_destroy function<br />
<code>&lt;?php<br />
unset($_SESSION['username']);<br />
?&gt;</code></p>
<p>The difference between unset() and session_destroy is that unset() merely free up the session variable while session_destroy will completely reset your session and the session data becomes unavailable.</p>
<p><code>&lt;?php<br />
session_destroy();<br />
?&gt;</code></p>
<p>To get the session id you can use the session_id()  function.It returns the session id for the curent session or an empty string if it is a new session.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/cookies-and-sessions-in-php.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating user defined functions and classes in PHP</title>
		<link>http://www.three2tango.com/techcorner/creating-user-defined-functions-and-classes-in-php.html/</link>
		<comments>http://www.three2tango.com/techcorner/creating-user-defined-functions-and-classes-in-php.html/#comments</comments>
		<pubDate>Mon, 25 May 2009 12:04:33 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[Classes in PHP]]></category>
		<category><![CDATA[functions in PHP]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=1115</guid>
		<description><![CDATA[This post covers the basics in creating user defined functions and classes in PHP.Like most other programming languages, PHP also offers you a wave of in built functions.But here lwe will see how to create user defined functions in PHP ansd also learn the basic of Object oriented concepts in PHP.You should make use of the classes and functions to make your code more readable and ordered.The various object oriented concepts like inheritance etc can be used to enhance the functionlity of your application by the use of classes.]]></description>
			<content:encoded><![CDATA[<p><strong>Functions:</strong></p>
<p>Like most other programming languages, PHP also offers you a wave of in built functions.But here lets see how to create user defined functions in PHP.</p>
<p>A function as you will know will be executed when the function is called.The basic syntax for the function is the same as you would see in most of the programming languages</p>
<blockquote><p>function function_name(list of parameters if any)<br />
{<br />
&#8211;function body&#8212;<br />
}</p></blockquote>
<p>Make sure that the function name does not start with a number.<br />
Lets see our first PHP program with a function</p>
<p><code>&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;?php<br />
function welcomemsg()<br />
{<br />
echo "and you are learning how to create functions in PHP" ;<br />
}<br />
echo "Welcome to three2tango.com";<br />
welcomemsg();<br />
?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<blockquote><p>Output: Welcome to three2tango.com and you are learning how to create functions in PHP</p></blockquote>
<p>This is a very basic example of a function with no parameters or returning any value.Now,lets create a function with parameters</p>
<p><code>&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;?php<br />
function addnumbers($x,$y)<br />
{<br />
$sum=$x+$y;<br />
return $sum;<br />
}<br />
$total=addnumbers(3,8);<br />
echo "Result of addition:".$total;<br />
&lt;/body&gt;<br />
&lt;html&gt;<br />
</code></p>
<blockquote><p>Output: Result of addition:11</p></blockquote>
<p>The above function addnumbers takes two arguments and also returns a value.Easy right?<br />
To make your code more readable,you might want to use functions.It also can save a page to be loaded again and again as the function is executed only when it is called.</p>
<p><strong>Classes:</strong></p>
<p>To enhance the Object oriented concepts in PHP,it also supports the use of classes.Recall that a class is just an aggregation of variables and functions, or in more technical terms we can define classes as those which define objects.</p>
<p>The syntax of a class:</p>
<blockquote><p>class class_name<br />
{<br />
//variables<br />
//functions<br />
}</p></blockquote>
<p>Every class has a constructor and it is usually the first function inside the class.The constructor is a function that has the same name as that of the class and is run every time an object of the class is created.</p>
<p>Lets first see a simple class having only variables</p>
<p><code>&lt;?php<br />
class Country<br />
{<br />
var $states=28;<br />
var $capital="New Delhi";<br />
}<br />
$india=new Country();//creating an object of the class<br />
echo "India  has ".$india-&gt;states."states and its capital is"$india-&gt;capital;<br />
?&gt;</code></p>
<blockquote><p>Output: India has 28 states and its capital is New Delhi.</p></blockquote>
<p>Note that variables declares in the class are preceded by the var keyword.Now lets see a class having a function</p>
<p><code>&lt;?php<br />
class Country<br />
{<br />
var $states=28;<br />
var $capital="New Delhi";<br />
function continent()<br />
{<br />
echo "Asia";<br />
}<br />
}<br />
$india=new Country();<br />
$india-&gt;region="Asia";<br />
echo "India  has ".$india-&gt;states."states and its capital is"$india-&gt;capital;<br />
echo "India lies in the continent of ". india-&gt;continent;<br />
?&gt;<br />
</code></p>
<blockquote><p>Output: India has 28 states and its capital is New Delhi India lies in the continent of Asia</p></blockquote>
<p>Finally lets see an example of a php class with constructors</p>
<p><code>&lt;?php<br />
class Country<br />
{<br />
var $states=28;<br />
var $capital="New Delhi";<br />
function continent($region)<br />
{<br />
$this-&gt;region=$region;// $this allows us to refer to the object even before knowing its name.<br />
}<br />
function stats()<br />
{<br />
return "This".get_class($this)." has".$this-&gt;states."states" and has its capital in".$this-&gt;capital."and lies in".$this-&gt;region;<br />
}<br />
}<br />
$india=new Country("Asia");<br />
echo "India:";<br />
echo $india-&gt;stats();<br />
?&gt;</code></p>
<blockquote><p>Output: India: This Country has 28 states and has its capital in New Delhi and lies in Asia</p></blockquote>
<p>The get_class() function is an in built function in PHP which will return the name of the classs of the object.Here the object created id India of the class Country and hence &#8220;Country&#8221; is returned.<br />
Here we have also seen how to add attributes to the objects.Note that we add the attribute &#8220;Asia&#8221; to the object &#8220;india&#8221;</p>
<p>This post covered the basics in creating user defined functions and classes in PHP.Make use of the classes and functions to make your code more readable and ordered.The various object oriented concepts like inheritance etc can be used to enhance the functionlity of your application by the use of classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/creating-user-defined-functions-and-classes-in-php.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Encryption in PHP using crypt()</title>
		<link>http://www.three2tango.com/techcorner/data-encryption-in-php-using-crypt.html/</link>
		<comments>http://www.three2tango.com/techcorner/data-encryption-in-php-using-crypt.html/#comments</comments>
		<pubDate>Sat, 02 May 2009 11:01:35 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[crypt()]]></category>
		<category><![CDATA[encryption in PHP]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=613</guid>
		<description><![CDATA[PHP provides you with the crypt() function for one way encryption of data.
For example,if you have a registration form to enter the password and suppose we require it to be secure,that is,to be saved in the database in the encrypted manner,we can use this function.
Basic syntax of the crypt() function is
crypt(your string,salt)
The salt parameter influences how the encryption will work
Mainly 4 types of salts are supported.
Two DES encryption salts
CRYPT_STD_DES(2 character salt)
CRYPT_EXT_DES(9 character salt)
and
CRYPT_MD5(12 character salt,starts with $1$)
CRYPT_BLOWFISH (16 character salt,starts with$2$ or $2a$)
Lets see the working of the crypt() in ...]]></description>
			<content:encoded><![CDATA[<p>PHP provides you with the crypt() function for one way encryption of data.<br />
For example,if you have a registration form to enter the password and suppose we require it to be secure,that is,to be saved in the database in the encrypted manner,we can use this function.</p>
<p>Basic syntax of the crypt() function is<br />
<strong>crypt(your string,salt)</strong></p>
<p>The salt parameter influences how the encryption will work</p>
<p>Mainly 4 types of salts are supported.<br />
Two DES encryption salts<br />
CRYPT_STD_DES(2 character salt)<br />
CRYPT_EXT_DES(9 character salt)<br />
and<br />
CRYPT_MD5(12 character salt,starts with $1$)<br />
CRYPT_BLOWFISH (16 character salt,starts with$2$ or $2a$)</p>
<p>Lets see the working of the crypt() in action<br />
<a href="http://www.three2tango.com/archives/595">Read Basics about PHP and MySQL first.</a></p>
<p>Firstly i have create table in database &#8220;test&#8221;.<br />
Table name=registration<br />
Fields<br />
uid varchar(255)<br />
pwd varchar(255)</p>
<p>I am trying to insert into this table,with the password in the  encrypted form.Here is the html form for this.</p>
<p><code>&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;form action="register.php" method="post"&gt;<br />
UserName&lt;input type="text" name="username" /&gt;<br />
Password &lt;input type="password" name="password" /&gt;<br />
&lt;input type="submit" /&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code><br />
Note that the form data is sent to register.php by the POST method.</p>
<p>Now lets see the register.php page</p>
<p><code>&lt;?php<br />
$mycon = mysql_connect("localhost","root","");<br />
if (!$mycon)<br />
{<br />
die('Could not connect: ' . mysql_error());<br />
}<br />
mysql_select_db("test", $mycon);<br />
$encryptedpwd=crypt($_POST['password'],'d4');<br />
echo $encryptedpwd;<br />
$sql="INSERT INTO Registration(uid,pwd) VALUES ('$_POST[username]','$encryptedpwd')";<br />
if (!mysql_query($sql,$mycon))<br />
{<br />
die('Error: ' . mysql_error());<br />
}<br />
echo "Sucessfully registerd";<br />
mysql_close($mycon)<br />
?&gt;</code><br />
Note that here i have used a standard DES encryption which has a 2 character salt &#8216;d4&#8242;.<br />
In the registration table,the password will be inserted in the encrypted format.</p>
<p>In the login form,we do the same thing.When crypt() is called,the password entered is encrypted and checked against the already encrypted password to see whether it matches. You will have to use the same salt you used earlier for this to work.</p>
<p>The crypt() using different types of salts</p>
<p>$encryptedpwd=crypt($_POST['password'] , &#8216;g477d.reg&#8217;);<br />
$encryptedpwd=crypt($_POST['password'] , &#8216;g477d.reg&#8217;);<br />
$encryptedpwd=crypt($_POST['password'] , &#8216;$1$ad235de$&#8217;);<br />
$encryptedpwd=crypt($_POST['password'] , &#8216;$2$dads&#8230;.$&#8217;);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/data-encryption-in-php-using-crypt.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and MySQL Basics</title>
		<link>http://www.three2tango.com/techcorner/php-and-mysql-basics.html/</link>
		<comments>http://www.three2tango.com/techcorner/php-and-mysql-basics.html/#comments</comments>
		<pubDate>Fri, 01 May 2009 10:01:44 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=595</guid>
		<description><![CDATA[PHP stands for Hypertext Preprocessor.PHP is a powerful server side scripting language for creating dynamic and interactive websites.The definite advantage of PHP over ASP.NET is that it free and can easily be embedded in html.PHP supports many databases(MY SQL,Oracle to name a few) and is cross platform(works under different platforms).
What you need:
In order to code in PHP you will need to install

PHP
MySQL database
Apache server(commonly used web server) or

You can install the WAMP server,which is a package that includes PHP,Apache and the MySQL database.
Follow this link to know how to install ...]]></description>
			<content:encoded><![CDATA[<p>PHP stands for Hypertext Preprocessor.PHP is a powerful server side scripting language for creating dynamic and interactive websites.The definite advantage of PHP over ASP.NET is that it free and can easily be embedded in html.PHP supports many databases(MY SQL,Oracle to name a few) and is cross platform(works under different platforms).</p>
<h4>What you need:</h4>
<p>In order to code in PHP you will need to install</p>
<ul>
<li>PHP</li>
<li>MySQL database</li>
<li>Apache server(commonly used web server) or</li>
</ul>
<p>You can install the WAMP server,which is a package that includes PHP,Apache and the MySQL database.</p>
<p><a href="http://www.shefeekj.com/wamp-server.html">Follow this link to know how to install WAMP</a></p>
<p>Basic PHP syntax<br />
A PHP block starts with the &lt;?php tag and ends with the ?&gt; tag.</p>
<h4>Your first PHP program:</h4>
<blockquote>
<p style="text-align: left;">&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;?php<br />
$txt1= &#8220;Welcome to www.three2tango.com&#8221;;<br />
echo $txt1;<br />
?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>echo is used for output to the screen.<br />
As shown above,a PHP variable starts with the $ sign.You would have noticed that the variable is not declared anywhere.PHP is a loosely coupled language and we do not need to declare the variable to use it.Based on the input to the variable,PHP converts the variable into the correct datatype.</p>
<p>In the example above PHP automatically converts txt1 to a string variable when &#8220;Welcome to www.three2tango.com&#8221; is assigned to it.</p>
<blockquote><p>&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;?php<br />
$txt1= &#8220;Welcome to www.three2tango.com&#8221;;<br />
$txt2=&#8221;And You are studying PHP&#8221;;<br />
echo $txt1.&#8221;".$txt2;<br />
?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>The above example will output &#8220;Welcome to www.three2tango.com And You are studying PHP&#8221;<br />
&#8216;.&#8217; is the concatenation operator in PHP.</p>
<h4>The $_GET and $_POST variables:</h4>
<p>The $_GET variable is used to collect values from a form with method=&#8221;get&#8221;.<br />
The $_POST variable is used to collect values from a form with method=&#8221;post&#8221;.<br />
In addition you can make use of the $_REQUEST variable to get the results from a form data sent with both GET and POST methods.</p>
<h4>MySQL and PHP:</h4>
<p>To use MySQL from the WAMP server,click on the WAMP server icon and select localhost.click on the &#8220;phpmyadmin&#8221; link to open the interface to the mySQL database.Here you can create the database and tables.</p>
<p>I created a database &#8220;test&#8221; and added a table &#8220;persons&#8221; with the fields firstname,lastname,city and address.</p>
<p>Suppose you want to insert data into the table and the display the data.<br />
First you create a html page from where you can input the values.The following is the html page.</p>
<blockquote><p>&lt;html&gt;<br />
&lt;body&gt;<br />
&lt;form action=&#8221;insert.php&#8221; method=&#8221;post&#8221;&gt;<br />
Firstname: &lt;input type=&#8221;text&#8221; name=&#8221;firstname&#8221; /&gt;<br />
Lastname: &lt;input type=&#8221;text&#8221; name=&#8221;lastname&#8221; /&gt;<br />
City: &lt;input type=&#8221;text&#8221; name=&#8221;city&#8221; /&gt;<br />
Address:&lt;input type=&#8221;text&#8221; name=&#8221;address&#8221;/&gt;<br />
&lt;input type=&#8221;submit&#8221; /&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>Note that i have used the POST method to send form data to insert.php.The insert.php file retrives values from the form using the $_POST variable, and also displays the inserted data.</p>
<p>Here is the insert.php code</p>
<blockquote><p>&lt;?php<br />
$mycon = mysql_connect(&#8220;localhost&#8221;,&#8221;root&#8221;,&#8221;");<br />
if (!$mycon)<br />
{<br />
die(&#8216;Could not connect: &#8216; . mysql_error());<br />
}</p>
<p>mysql_select_db(&#8220;test&#8221;, $mycon);</p>
<p>$sql=&#8221;INSERT INTO Persons (LastName,FirstName,City,Address)<br />
VALUES<br />
(&#8216;$_POST[lastname]&#8216;,&#8217;$_POST[firstname]&#8216;,&#8217;$_POST[city]&#8216;,&#8217;$_POST[address]&#8216;)&#8221;;</p>
<p>if (!mysql_query($sql,$mycon))<br />
{<br />
die(&#8216;Error: &#8216; . mysql_error());<br />
}<br />
echo &#8220;1 record added&#8221;;</p>
<p>$result=mysql_query(&#8220;select * from persons order by firstname&#8221;);</p>
<p>echo &#8220;&lt;table border=&#8217;1&#8242;&gt;<br />
&lt;tr&gt;<br />
&lt;th&gt;Firstname&lt;/th&gt;<br />
&lt;th&gt;Lastname&lt;/th&gt;<br />
&lt;th&gt;City&lt;/th&gt;<br />
&lt;th&gt;Address&lt;/th&gt;<br />
&lt;/tr&gt;&#8221;;</p>
<p>while($row = mysql_fetch_array($result))<br />
{<br />
echo &#8220;&lt;tr&gt;&#8221;;<br />
echo &#8220;&lt;td&gt;&#8221; . $row['FirstName'] . &#8220;&lt;/td&gt;&#8221;;<br />
echo &#8220;&lt;td&gt;&#8221; . $row['LastName'] . &#8220;&lt;/td&gt;&#8221;;<br />
echo &#8220;&lt;td&gt;&#8221; . $row['City'].&#8221;&lt;/td&gt;&#8221;;<br />
echo &#8220;&lt;td&gt;&#8221; . $row['Address'].&#8221;&lt;/td&gt;&#8221;;<br />
echo &#8220;&lt;/tr&gt;&#8221;;<br />
}<br />
echo &#8220;&lt;/table&gt;&#8221;;<br />
mysql_close($mycon)<br />
?&gt;</p></blockquote>
<p>Here the output of the above code:</p>
<p style="text-align: center;"><a href="http://www.three2tango.com/wp-content/uploads/2009/05/output.jpg"><img class="aligncenter size-medium wp-image-596" style="border: 1px solid black;" title="ScreenShot" src="http://www.three2tango.com/wp-content/uploads/2009/05/output-300x145.jpg" alt="ScreenShot" width="300" height="145" /></a></p>
<p>mysql_connect is used to conect to the database.<br />
mysql_close closes the connection.<br />
mysql_select_db connects to the database-in the above example,itr connects to the test database.<br />
mysql_query performs the query on the selected database<br />
mysql_fetch_array gets the result of the query row after row in an associative array</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/php-and-mysql-basics.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

