<?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>Technotip.com &#187; PHP</title>
	<atom:link href="http://technotip.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://technotip.com</link>
	<description>Code is poetry!</description>
	<lastBuildDate>Sat, 04 Feb 2012 07:47:57 +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>Insert And Extract/Fetch Data From Database: PHP Script</title>
		<link>http://technotip.com/570/insert-extractfetch-data-from-database-php-script/</link>
		<comments>http://technotip.com/570/insert-extractfetch-data-from-database-php-script/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 21:10:19 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=570</guid>
		<description><![CDATA[What to expect ? Using PHP script insert user entered data/information into database and extract/fetch data stored in database and display it on the browser. This video tutorial also teaches the MySQL queries. In this video tutorial we have used a readymade form which uses POST method to pass the user entered information. To watch [...]
Related posts:<ol>
<li><a href='http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/' rel='bookmark' title='Develop User Signup and Login forms: PHP &amp; MySQL'>Develop User Signup and Login forms: PHP &#038; MySQL</a></li>
<li><a href='http://technotip.com/559/post-method-in-action-simple-form/' rel='bookmark' title='POST Method In Action: Simple Form'>POST Method In Action: Simple Form</a></li>
<li><a href='http://technotip.com/402/store-page-view-count-in-session-variable-php/' rel='bookmark' title='Store Page View Count In Session Variable: PHP'>Store Page View Count In Session Variable: PHP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>What to expect ?</strong><br />
Using PHP script insert user entered data/information into database and extract/fetch data stored in database and display it on the browser.<br />
This video tutorial also teaches the MySQL queries.</p>
<p>In this video tutorial we have used a readymade form which uses POST method to pass the user entered information. To watch the coding/designing of this form go to <a href="http://technotip.com/559/post-method-in-action-simple-form/">POST Method In Action: Simple Form</a></p>
<p><strong>Video Tutorial</strong><br />
<center><br />
<iframe title="YouTube video player" width="630" height="385" src="http://www.youtube.com/embed/4oViKzEDiMo?rel=0" frameborder="0" allowfullscreen></iframe><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=4oViKzEDiMo">http://www.youtube.com/watch?v=4oViKzEDiMo</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /></p>
<p><strong>MySQL Commands and Uses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql &gt; drop database abc;</pre></div></div>

<p>This command will delete the database by name <strong>abc</strong>, if its already present.<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql &gt; create database abc;</pre></div></div>

<p>This MySQL command creates a new database by name <strong>abc</strong>.<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql &gt; use abc;</pre></div></div>

<p>After creating the database <strong>abc</strong>, we must tell the console that we want to operate on the newly created database. i.e., <i>use abc;</i><br />
</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql &gt; create table bbc(name varchar(15), company varchar(20));</pre></div></div>

<p>This MySQL command is used to create a table by name <strong>bbc</strong> with two string type data fields <strong>name</strong> and <strong>company</strong> with character length of 15 and 20 respectively.<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql &gt; desc bbc;</pre></div></div>

<p>This shows the description or the structure of the table.<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql &gt; select * from bbc;</pre></div></div>

<p>This returns all the contents stored in the table bbc.</p>
<p><strong>PHP Script</strong></p>
<p><strong>Connecting the PHP Script to database</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;?php
	$conn = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
	$db      = mysql_select_db(&quot;abc&quot;,$conn);
?&gt;</pre></div></div>

<p>mysql_connect() is a standard function which takes 3 parameters. First parameter is host name, second parameter is the MySQL username, and the 3rd parameter is the MySQL password.<br />
mysql_select_db() is also a php standard function. Firs parameter is the database name, with which you want the script to be connected to, and the second parameter is optional.<br />
<strong>NOTE:</strong> We can put this database connection code inside a separate file and include it inside whichever script we want using include(); or include_once(); function. This way we can reduce the coding and this helps a lot while we are editing this information.</p>
<p><strong>Compete Source Code</strong><br />
<strong>postform.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
 &lt;head&gt;&lt;title&gt;POST Method in Action&lt;/title&gt;&lt;/head&gt;
 &lt;body&gt;
	&lt;form action=&quot;post.php&quot; method=&quot;post&quot;&gt;
		Name &lt;input type=&quot;text&quot; name=&quot;user&quot;&gt;&lt;br /&gt;
		Company&lt;input type=&quot;text&quot; name=&quot;comp&quot;&gt;&lt;br /&gt;
		&lt;input type=&quot;submit&quot; value=&quot; Submit Info&quot;&gt;
	&lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This is a simple form which contains 2 input fields(user and comp) and a submit button. It uses POST method to pass the user submitted information/data.<br />
<br />
<strong>post.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
	$conn = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
	$db      = mysql_select_db(&quot;abc&quot;,$conn);
?&gt;
&nbsp;
&lt;?php
&nbsp;
	$name       =	  $_POST['user'];
	$company = 	  $_POST['comp'];
&nbsp;
	# echo &quot;My name is $name &lt;br /&gt; And I'm the CEO of my company {$company}&quot;
&nbsp;
	$sql     = &quot;INSERT into bbc values('$name','$company')&quot;;
	$qury  = mysql_query($sql);
&nbsp;
	if(!$qury)
		echo mysql_error();
	else
	{
		echo &quot;Successfully Inserted&lt;br /&gt;&quot;;
		echo &quot;&lt;a href='show.php'&gt;View Result&lt;/a&gt;&quot;;
	}
?&gt;</pre></td></tr></table></div>

<p>After storing the information passed by the user inside $name and $company variables, we use the MySQL query to store this data into the database.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">	$sql     = &quot;INSERT into bbc values('$name','$company')&quot;;</pre></div></div>

<p>This MySQL query is stored into $sql variable and is passed to a standard PHP function for execution. i.e., mysql_query($sql);<br />
Based on the result of the execution of the query, we show the proper messages using <strong>if</strong> statement.</p>
<p>mysql_error() is a standard PHP error function. This helps a lot in development stage, as it shows a descriptive error message. It is not advised to have this error function in the script at deployment stage.</p>
<p><strong>show.php</strong><br />
If the query is executed successfully, a link to show.php file is shown and a &#8220;Successfully Inserted&#8221; message will be displayed on the browser.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
	$conn = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
	$db      = mysql_select_db(&quot;abc&quot;,$conn);
?&gt;
&nbsp;
&lt;?php
&nbsp;
	echo &quot;&lt;ul&gt;&quot;;
	$sql = &quot;select * from bbc&quot;;
&nbsp;
	$qury = mysql_query($sql);
&nbsp;
	while($row = mysql_fetch_array($qury))
		echo &quot;&lt;li&gt;Name: $row[0]&lt;/li&gt;&lt;li&gt;Company: $row[1]&lt;/li&gt;&lt;br /&gt;&quot;;
&nbsp;
	echo &quot;&lt;/ul&gt;&quot;;
&nbsp;
?&gt;</pre></td></tr></table></div>

<p>We have already explained the <i>select</i> query above.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">$row = mysql_fetch_array($qury)</pre></div></div>

<p>This PHP function gets all the result stored in $query and stores it inside <strong>$row</strong> variable in the form of an array.</p>
<p>If we put this above statement inside a While loop, the loop terminates once there are no more elements in the $query variable.</p>
<p>Now, echo/print the contents of the $row variable to get the contents being fetched by the database using SELECT query.</p>
<p>We can either use the indexing like: $row[0], $row[1] etc or we can directly mention the database field names to reduce confusion i.e., $row[name], $row[company] etc.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/' rel='bookmark' title='Develop User Signup and Login forms: PHP &amp; MySQL'>Develop User Signup and Login forms: PHP &#038; MySQL</a></li>
<li><a href='http://technotip.com/559/post-method-in-action-simple-form/' rel='bookmark' title='POST Method In Action: Simple Form'>POST Method In Action: Simple Form</a></li>
<li><a href='http://technotip.com/402/store-page-view-count-in-session-variable-php/' rel='bookmark' title='Store Page View Count In Session Variable: PHP'>Store Page View Count In Session Variable: PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/570/insert-extractfetch-data-from-database-php-script/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>POST Method In Action: Simple Form</title>
		<link>http://technotip.com/559/post-method-in-action-simple-form/</link>
		<comments>http://technotip.com/559/post-method-in-action-simple-form/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 17:31:10 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[POST Method]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=559</guid>
		<description><![CDATA[This Basic PHP tutorial illustrates the usage of POST method, with the help of a simple HTML form. It echo&#8217;s/print&#8217;s the user entered information on to the browser by passing it via POST method. If you are sending sensitive informations like credit card number or your password, then make sure to use POST method. If [...]
Related posts:<ol>
<li><a href='http://technotip.com/551/get-method-in-action-simple-form/' rel='bookmark' title='GET Method In Action: Simple Form'>GET Method In Action: Simple Form</a></li>
<li><a href='http://technotip.com/526/wordpress-username-password-for-your-application-login/' rel='bookmark' title='WordPress Username &amp; Password For Your Application Login'>WordPress Username &#038; Password For Your Application Login</a></li>
<li><a href='http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/' rel='bookmark' title='Develop User Signup and Login forms: PHP &amp; MySQL'>Develop User Signup and Login forms: PHP &#038; MySQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This Basic PHP tutorial illustrates the usage of POST method, with the help of a simple HTML form. It echo&#8217;s/print&#8217;s the user entered information on to the browser by passing it via POST method.</p>
<p>If you are sending sensitive informations like credit card number or your password, then make sure to use POST method. If you use GET method, it will reveal all the information in the address bar. With POST method, the parameters are not shown and hence not visible for people who might be stalking you!</p>
<p><strong>Source Code</strong><br />
We have purposefully kept this example super simple, as this is a basic thing in PHP and complex things may confuse beginners.</p>
<p><strong>postform.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
 &lt;head&gt;&lt;title&gt;POST Method in Action&lt;/title&gt;&lt;/head&gt;
 &lt;body&gt;
	&lt;form action=&quot;post.php&quot; method=&quot;post&quot;&gt;
		Name &lt;input type=&quot;text&quot; name=&quot;user&quot;&gt;&lt;br /&gt;
		Company&lt;input type=&quot;text&quot; name=&quot;comp&quot;&gt;&lt;br /&gt;
		&lt;input type=&quot;submit&quot; value=&quot; Submit Info&quot;&gt;
	&lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This is a simple form which contains 2 input fields(<i>user</i> and <i>comp</i>) and a submit button. Observe the <i>method</i> used: its POST method.<br />
We have given unique name to each input fields, so that the values are passed to the post.php</p>
<p><strong>post.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
&nbsp;
	$name       =	  $_POST['user'];
	$company  = 	  $_POST['comp'];
&nbsp;
	echo &quot;My name is $name &lt;br /&gt; And I'm the CEO of my company {$company}&quot;;
&nbsp;
?&gt;</pre></td></tr></table></div>

<p>This is the actual file where the action takes place. All the information is passed on to post.php via postform.php file. Using $_POST[] we receive the values and store it in the local variables. Using the values in these local variables we can do whatever we want to do: like print it on the browser(as we do in this tutorial), insert it into database etc.</p>
<p><strong>Video Tutorial:</strong><br />
<center><br />
<iframe title="YouTube video player" width="630" height="385" src="http://www.youtube.com/embed/XrX02OSbPt4?rel=0" frameborder="0" allowfullscreen></iframe><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=XrX02OSbPt4">http://www.youtube.com/watch?v=XrX02OSbPt4</a> [Watch the Video In Full Screen + HD]</div>
<p><br style="clear: both;" /></p>
<p><strong>Advantages of using POST method over GET method</strong><br />
The POST method does not have any restriction on data size to be sent.<br />
The POST method can be used to send ASCII as well as binary data.<br />
The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/551/get-method-in-action-simple-form/' rel='bookmark' title='GET Method In Action: Simple Form'>GET Method In Action: Simple Form</a></li>
<li><a href='http://technotip.com/526/wordpress-username-password-for-your-application-login/' rel='bookmark' title='WordPress Username &amp; Password For Your Application Login'>WordPress Username &#038; Password For Your Application Login</a></li>
<li><a href='http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/' rel='bookmark' title='Develop User Signup and Login forms: PHP &amp; MySQL'>Develop User Signup and Login forms: PHP &#038; MySQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/559/post-method-in-action-simple-form/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GET Method In Action: Simple Form</title>
		<link>http://technotip.com/551/get-method-in-action-simple-form/</link>
		<comments>http://technotip.com/551/get-method-in-action-simple-form/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 10:38:23 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Advantages of GET over POST]]></category>
		<category><![CDATA[GET Method]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=551</guid>
		<description><![CDATA[This Basic PHP tutorial illustrates the usage of GET method, with the help of a simple HTML form. It echo&#8217;s/print&#8217;s the user entered information on to the browser by passing it via GET method. It also tells one big advantage of GET method over POST method. Source Code We have purposefully kept this example super [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>This Basic PHP tutorial illustrates the usage of GET method, with the help of a simple HTML form. It echo&#8217;s/print&#8217;s the user entered information on to the browser by passing it via GET method.<br />
It also tells one big advantage of GET method over POST method.</p>
<p><strong>Source Code</strong><br />
We have purposefully kept this example super simple, as this is a basic thing in PHP and complex things may confuse beginners.</p>
<p><strong>getForm.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
 &lt;head&gt;&lt;title&gt;Form using GET method&lt;/title&gt;&lt;/head&gt;
 &lt;body&gt;
	&lt;form action=&quot;get.php&quot; method=&quot;get&quot;&gt;
		Name &lt;input type=&quot;text&quot; name=&quot;uname&quot;&gt;&lt;br /&gt;
		Age    &lt;input type=&quot;text&quot; name=&quot;age&quot;&gt;&lt;br /&gt;
		&lt;input type=&quot;submit&quot; value=&quot;Submit Info&quot;&gt;
	&lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This is a simple form which contains 2 input fields and a submit button. Observe the <i>method</i> used: its GET method.<br />
We have given unique name to each input fields, so that the values are passed to the get.php</p>
<p><strong>get.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
&nbsp;
	$name = $_GET['uname'];
	$age     = $_GET['age'];
&nbsp;
	echo &quot;Name is $name &lt;br /&gt; Age is $age&quot;;
&nbsp;
?&gt;</pre></td></tr></table></div>

<p>This is the actual file where the action takes place. All the information is passed on to this file via getForm.php file. Using $_GET[] we receive the values and store it in the local variables. Using the values in these local variables we can do whatever we want to do: like print it on the browser(as we do in this tutorial), insert it into database etc.</p>
<p><strong>Video Tutorial:</strong><br />
<center><br />
<iframe title="YouTube video player" width="630" height="385" src="http://www.youtube.com/embed/3zmH6zXyrx8?rel=0" frameborder="0" allowfullscreen></iframe><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/embed/3zmH6zXyrx8">http://www.youtube.com/embed/3zmH6zXyrx8</a> [Watch the Video In Full Screen + HD]</div>
<p><br style="clear: both;" /></p>
<p><strong>Advantages of using GET method over POST method</strong><br />
One of the biggest advantage of using GET method is, we can send the URL in the address bar to a friend over email as it contains the name and associated value in the URL. But in post method, you will neither get the name nor the value in the address bar, hence you can&#8217;t send it over to any one. If you still send, it may not make any sense!</p>
<p><strong>Ex:</strong> You Google for the term &#8220;technotip&#8221;. Copy the URL in the address bar and can send it to your friend. Many bookmarking sites use GET method, because users must be able to copy and paste the url and pass it on to their friends. If they used POST method, then its of no use to send the url, since the URL before and after querying remains same!</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/551/get-method-in-action-simple-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Username &amp; Password For Your Application Login</title>
		<link>http://technotip.com/526/wordpress-username-password-for-your-application-login/</link>
		<comments>http://technotip.com/526/wordpress-username-password-for-your-application-login/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 00:21:14 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[app credentials]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Custom Application]]></category>
		<category><![CDATA[Self hosted]]></category>
		<category><![CDATA[username password combination]]></category>
		<category><![CDATA[WordPress database]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=526</guid>
		<description><![CDATA[Today we shall learn a simple method of using Self Hosted WordPress&#8217;s Credentials(username and password) to log into your custom application.. You may ask, &#8220;Well, why we should use this?&#8221; The reason is, because WordPress is an opensource script which is constantly improving and has a strong security. And this approach provides easy integration of [...]
Related posts:<ol>
<li><a href='http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/' rel='bookmark' title='Develop User Signup and Login forms: PHP &amp; MySQL'>Develop User Signup and Login forms: PHP &#038; MySQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Today we shall learn a simple method of using Self Hosted WordPress&#8217;s Credentials(username and password) to log into your custom application..</p>
<p>You may ask, &#8220;Well, why we should use this?&#8221;<br />
The reason is, because WordPress is an opensource script which is constantly improving and has a strong security. And this approach provides easy integration of our custom application with WordPress.</p>
<p>In this tutorial we are using a simple login form(loginform.php) wherein our custom application&#8217;s users enter their username and password, which is sent to login.php file, where it is passed on to a standerd WordPress function for processing. Based on the result returned by this function, we decide the success and failure of user login.</p>
<p><center><img width="540" height="565" src="http://technotip.com/wp-content/uploads/php/WordPress-Custom-App.png" alt="WordPress Custom App WordPress Username & Password For Your Application Login"  title="WordPress Username & Password For Your Application Login" /></center></p>
<p><strong>Complete Source Code:</strong>(loginform.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;User Login Form&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
	&lt;form action=&quot;login.php&quot; method=&quot;post&quot;&gt;
		Username: &lt;input type=&quot;text&quot; name=&quot;txtuid&quot;&gt;&lt;br /&gt;
		Password:  &lt;input type=&quot;password&quot; name=&quot;txtpwd&quot;&gt;&lt;br /&gt;
		&lt;input type=&quot;submit&quot; value=&quot; LogIn &quot;&gt;
  	&lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This is simple HTML login form with two input fields, each having unique names to it. We are using post method  here, as we will be passing sensitive information i.e., password.</p>
<p><strong>login.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php require('..\wp-blog-header.php'); ?&gt;
&nbsp;
&lt;?php
&nbsp;
	$uid = $_POST['txtuid'];
	$pwd = $_POST['txtpwd'];
&nbsp;
	if(!user_pass_ok( $uid, $pwd ))
		echo &quot;Login Failed!&quot;;
	else
		echo &quot;Welcome {$uid}!!&quot;;
&nbsp;
?&gt;</pre></td></tr></table></div>

<p>We MUST include <strong>wp-blog-header.php</strong> file into our login.php file. wp-blog-header.php is a core WordPress file found in the root of the WordPress installation.<br />
<strong>user_pass_ok()</strong> is a standard WordPress function which takes a minimum of two arguments. One is username and the other is password.<br />
Once we pass these parameters to this function, it checks for the username and password combination in the WordPress&#8217;s database and returns <strong>true</strong> if present and <strong>false</strong> if not present. Based on this result we authenticate the user.</p>
<p>If user_pass_ok($username, $password) returns true, then the username and password combination passed is present in the WordPress database, hence login successful. If it returns false, then the username and password combination passed is NOT present in the WordPress database, hence login failed.</p>
<p><strong>Video Tutorial:</strong><br />
<center><br />
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="630" height="385" src="http://www.youtube.com/embed/uSRkv2jfPG0?rel=0" frameborder="0" allowFullScreen></iframe><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=uSRkv2jfPG0">http://www.youtube.com/watch?v=uSRkv2jfPG0</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /></p>
<p>At the time of recording this video, we have WordPress 3.0.4 as the latest version. The above tutorial works for all the versions of WordPress 3.0.4 and below. We don&#8217;t know when WordPress folks will change this method of authentication in future versions of WordPress.</p>
<p>Please share any such WordPress techniques you know, in the comment section. </p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/' rel='bookmark' title='Develop User Signup and Login forms: PHP &amp; MySQL'>Develop User Signup and Login forms: PHP &#038; MySQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/526/wordpress-username-password-for-your-application-login/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Develop User Signup and Login forms: PHP &amp; MySQL</title>
		<link>http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/</link>
		<comments>http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 04:01:41 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=411</guid>
		<description><![CDATA[PHP &#038; MySQL tutorial to develop signup form and store user information in a database and using signin or login form we compare for the correct username and password combination in our database. We also use session and demonstrate session_start(), session_unset(), session_destroy(). This tutorial is very important for any of your projects where you want [...]
Related posts:<ol>
<li><a href='http://technotip.com/402/store-page-view-count-in-session-variable-php/' rel='bookmark' title='Store Page View Count In Session Variable: PHP'>Store Page View Count In Session Variable: PHP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>PHP &#038; MySQL tutorial to develop signup form and store user information in a database and using  signin or login form we compare for the correct username and password combination in our database. We also use session and demonstrate session_start(), session_unset(), session_destroy(). </p>
<p><center><img src="http://technotip.com/wp-content/uploads/php/php-login-session.png" alt="php login session Develop User Signup and Login forms: PHP & MySQL" width="596" height="269" title="Develop User Signup and Login forms: PHP & MySQL" /></center></p>
<p>This tutorial is very important for any of your projects where you want to implement authentication: user signup and signin. So this is a crucial part of your online application. So better spend some time to understand the working. Watch the video and try to code on your own. And please make sure to contribute back to the community by commenting and sharing what you have learnt, in the comment section below.</p>
<p><strong>Video Tutorial:</strong></p>
<p><center><iframe title="YouTube video player" class="youtube-player" type="text/html" width="626" height="385" src="http://www.youtube.com/embed/mn0ucCuNOTI?rel=0" frameborder="0" allowFullScreen></iframe><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=mn0ucCuNOTI">http://www.youtube.com/watch?v=mn0ucCuNOTI</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /><br />
In this tutorial we are using MySql database, PHP, and some HTML coding to design the forms.</p>
<p><strong>Complete Source Code and Explanation:</strong><br />
<strong>For Database connectivity:</strong>(db.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
     $conn = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
     $db   = mysql_select_db(&quot;technotip&quot;,$conn);
?&gt;</pre></td></tr></table></div>

<p>Instead of writing the database information again and again, we have moved this to one file(db.php) and call/include that file in all the scripts which needs to connect with the database.<br />
Here localhost is the hostname. In 95% of the time the hostname will be localhost. If you are using a grid based hosting service, then it will be your grid number followed by .gridserver.com ex: xxxx.gridserver.com</p>
<p>We are using localhost, <strong>root </strong>is its username. We do not have any password, so we have left the next field blank.</p>
<p>Next line of code is to select the database present in our localhost. Here we have created a database called <strong>technotip</strong>. Below is the MySQL syntax to create the database.<br />
<strong>Creating Database:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">mysql&gt; create database technotip;
mysql&gt; use technotip;</pre></td></tr></table></div>

<p>First line of code is to create the database, and the next line is to start making use of the created database.</p>
<p><strong>Table Creation:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql&gt; CREATE table phplogin( id int, username varchar(15), password varchar(20));</pre></div></div>

<p>To keep things simple, we are creating only 3 fields in the table: id, username, password.</p>
<p><strong>To Check the table description/structure:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql&gt; desc phplogin;</pre></div></div>

<p><strong>To see the table entries:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">mysql&gt; SELECT * from phplogin;</pre></div></div>

<p>
<strong>A Form for People To SignUp</strong>(signupform.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="language" style="font-family:monospace;"> &lt;html&gt;
        &lt;form action=&quot;signup.php&quot; method=&quot;post&quot;&gt;
              Username:&lt;input type=&quot;text&quot; name=&quot;n&quot;&gt;&lt;br /&gt;
              Password:&lt;input type=&quot;password&quot; name=&quot;p&quot;&gt;&lt;br /&gt;
              id      :&lt;input type=&quot;text&quot; name=&quot;id&quot;&gt;&lt;br /&gt;
              &lt;input type=&quot;submit&quot;&gt;
        &lt;/form&gt;
 &lt;/html&gt;</pre></td></tr></table></div>

<p>In signupform.php we are using <strong>post </strong>method, because we will be using password and it should not be shown in the address bar of the user!<br />
Let the <strong>name</strong> for each <strong>input</strong> field be unique, as we will be using this to receive the user input data in another file which is pointed by form <strong>action</strong>.</p>
<p><strong>GET v/s POST method</strong><br />
The GET method produces a long string that appears in your server logs and in the browser&#8217;s address bar.<br />
The GET method is restricted to send upto 1024 characters only.<br />
Never use GET method if you have password or other sensitive information to be sent to the server.<br />
GET can&#8217;t be used to send binary data, like images or word documents, to the server.<br />
The data sent by GET method can be accessed using QUERY_STRING environment variable.<br />
<br />
The POST method does not have any restriction on data size to be sent.<br />
The POST method can be used to send ASCII as well as binary data.<br />
The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.</p>
<p><strong>signup.php file</strong><br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php include_once(&quot;db.php&quot;); ?&gt;
&nbsp;
&lt;?php
           $user = $_POST['n'];
           $pass = $_POST['p'];
           $id = $_POST['id'];
        #$sql = &quot;INSERT into phplogin values(&quot;.$id.&quot;,'&quot;.$user.&quot;','&quot;.$pass.&quot;')&quot;;
          $sql = &quot;INSERT into phplogin values($id,'$user','$pass')&quot;;
           $qury = mysql_query($sql);
&nbsp;
        #  INSERT into phplogin values(
        #   1,
        #   'satish',
        #   'satish');
&nbsp;
        if(!$qury)
        {
                  echo &quot;Failed &quot;.mysql_error();
                  echo &quot;&lt;br /&gt;&lt;a href='signupform.php'&gt;SignUp&lt;/a&gt;&quot;;
                  echo &quot;&lt;br /&gt;&lt;a href='signinform.php'&gt;SignIn&lt;/a&gt;&quot;;
        }
        else
        {
                  echo &quot;Successful&quot;;
                  echo &quot;&lt;br /&gt;&lt;a href='signupform.php'&gt;SignUp&lt;/a&gt;&quot;;
                  echo &quot;&lt;br /&gt;&lt;a href='signinform.php'&gt;SignIn&lt;/a&gt;&quot;;
        }
?&gt;</pre></td></tr></table></div>

<p>Using <strong>include_once()</strong>, we are including the file db.php By including this file, we automatically get connected to the database.<br />
We use <strong>$_POST</strong> because we have used <strong>post</strong> method in signupform.php form.<br />
We can use either of the two MySQL query to insert the values into our table <strong>phplogin</strong>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">       $sql = &quot;INSERT into phplogin values(&quot;.$id.&quot;,'&quot;.$user.&quot;','&quot;.$pass.&quot;')&quot;;
                                   OR
       $sql = &quot;INSERT into phplogin values($id,'$user','$pass')&quot;;</pre></td></tr></table></div>

<p>Integer values need not be enclosed within single quotes, but the string variables(and values) must be enclosed within single quotation mark.</p>
<p><strong>mysql_query()</strong> is used to execute the query. You can directly pass the query as parameter to this standard PHP function.<br />
Based on the result of execution of above query we display a &#8220;Success&#8221; or &#8220;Failure&#8221; message and display some HTML links for further navigation.</p>
<p>
<strong>Login Form:</strong> (signinform.php)<br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
       &lt;form action=&quot;signin.php&quot; method=&quot;post&quot;&gt;
              username: &lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;&lt;br /&gt;
              password: &lt;input type=&quot;password&quot; name=&quot;pwd&quot;&gt;&lt;br /&gt;
              &lt;input type=&quot;submit&quot;&gt;
       &lt;/form&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This is same as signupform.php form, with minor modification to the input field. And the form <strong>action</strong> is pointing to signin.php file. Here also we are using <strong>post</strong> method.<br />
<br />
<strong>signin.php</strong><br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php 
&nbsp;
  include_once(&quot;db.php&quot;); 
  session_start();
&nbsp;
?&gt;
&nbsp;
&lt;?php
&nbsp;
     $uname = $_POST['name'];
     $pass = $_POST['pwd'];
&nbsp;
     $sql = &quot;SELECT count(*) FROM phplogin WHERE(
     username='&quot;.$uname.&quot;' and  password='&quot;.$pass.&quot;')&quot;;
&nbsp;
&nbsp;
#     SELECT count(*) FROM phplogin WHERE(
#     username='$uname' and  password='$pass');
&nbsp;
      $qury = mysql_query($sql);
&nbsp;
      $result = mysql_fetch_array($qury);
&nbsp;
      if($result[0]&gt;0)
      {
        echo &quot;Successful Login!&quot;;
        $_SESSION['userName'] = $uname;
        echo &quot;&lt;br /&gt;Welcome &quot;.$_SESSION['userName'].&quot;!&quot;;
        echo &quot;&lt;br /&gt;&lt;a href='signupform.php'&gt;SignUp&lt;/a&gt;&quot;;
        echo &quot;&lt;br /&gt;&lt;a href='signinform.php'&gt;SignIn&lt;/a&gt;&quot;;
        echo &quot;&lt;br /&gt;&lt;a href='logout.php'&gt;LogOut&lt;/a&gt;&quot;;
      }
      else
      {
        echo &quot;Login Failed&quot;;
        echo &quot;&lt;br /&gt;&lt;a href='signupform.php'&gt;SignUp&lt;/a&gt;&quot;;
        echo &quot;&lt;br /&gt;&lt;a href='signinform.php'&gt;SignIn&lt;/a&gt;&quot;;
      }
?&gt;</pre></td></tr></table></div>

<p>First we include the db.php inorder to connect to the database, so that we can compare the user entered credentials with the actual username and password present in our database.<br />
Here we are also starting the session. session_start() is the start call for the session and is a mandatory step, if you want to use session in any of your PHP script.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">   $sql = &quot;SELECT count(*) FROM phplogin WHERE(
     username='&quot;.$uname.&quot;' and  password='&quot;.$pass.&quot;')&quot;;</pre></td></tr></table></div>

<p>Using above MySQL query, we pass the user submitted username and password to our table and check if there is any presence of such combination of username and password. If the result is 1, then the username and password combination is present. If it returns 0, then there are no such a combination of username and password in the database: that means, login failed.</p>
<p>So, according to the result obtained we display the message and further give some links for navigation purpose.</p>
<p>If the login is successful, then we create a session variable with name <strong>userName</strong> and then assign the username to it.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">        $_SESSION['userName'] = $uname;
        echo &quot;&lt;br /&gt;Welcome &quot;.$_SESSION['userName'].&quot;!&quot;;</pre></div></div>

<p>and we display Welcome userName! message, which looks like a customized welcome for each person who logs in successfully.<br />
Once the user is logged in successfully, we provide a link to log out. Which is explained after the below snippet of code.</p>
<p>
<strong>Logout</strong> (logout.php)<br />
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
&nbsp;
	session_start(); # Starts the session
&nbsp;
	session_unset(); #removes all the variables in the session
&nbsp;
	session_destroy(); #destroys the session
&nbsp;
	if(!$_SESSION['userName'])
   		echo &quot;Successfully logged out!&lt;br /&gt;&quot;;
	else
   		 echo &quot;Error Occured!!&lt;br /&gt;&quot;;
&nbsp;
?&gt;</pre></td></tr></table></div>

<p>Above code is to illustrate a simple way of working of session. </p>
<p>	session_start(); # To Start the session</p>
<p>	session_unset(); # Unsets/Removes all the variables in the session</p>
<p>	session_destroy(); # Destroys the session</p>
<p>To demonstrate whether the logout process has removed/destroyed the set session variable, we have used the <strong>if</strong> statement, where in we check if the session variable is set or not. If still set, then  the logout process isn&#8217;t working. If the session variable is destroyed/unset, then the logout successful message is displayed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">	if(!$_SESSION['userName'])
   		echo &quot;Successfully logged out!&lt;br /&gt;&quot;;
	else
   		 echo &quot;Error Occurred!!&lt;br /&gt;&quot;;</pre></td></tr></table></div>

<p>In above tutorial we have taken much time to link to signup and signin forms, this may look trivial; but in practice these are very important for better user experience and usability factor. So make sure you provide options for your users so that they can do something when they are landed on a page. If the page is empty and there are no links to navigate, then the user may get puzzled! Instead, if you have links to the profile and a log out link, then the user can choose, where to go next.</p>
<p>Please share the above video tutorial with your friends on Facebook, Twitter etc, and subscribe to our blog and YouTube channel. All the best for your application development. We are excited and eager to hear about your application development in the comment section.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/402/store-page-view-count-in-session-variable-php/' rel='bookmark' title='Store Page View Count In Session Variable: PHP'>Store Page View Count In Session Variable: PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/411/develop-user-signup-and-login-forms-php-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Store Page View Count In Session Variable: PHP</title>
		<link>http://technotip.com/402/store-page-view-count-in-session-variable-php/</link>
		<comments>http://technotip.com/402/store-page-view-count-in-session-variable-php/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 15:56:46 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=402</guid>
		<description><![CDATA[PHP program to store page views count in SESSION, to increment the count on each refresh, and to show the count on web page. Session: A session is specific to the user and for each user a new session is created to track all the request from that user. Every user has a separate session [...]
Related posts:<ol>
<li><a href='http://technotip.com/279/dynamic-page-creation-php/' rel='bookmark' title='Dynamic Page Creation: PHP'>Dynamic Page Creation: PHP</a></li>
<li><a href='http://technotip.com/231/return-multiple-values-function-arrays-php/' rel='bookmark' title='Return Multiple Values From Function Using Arrays In PHP'>Return Multiple Values From Function Using Arrays In PHP</a></li>
<li><a href='http://technotip.com/387/randomly-display-some-images-from-a-set-of-images-php/' rel='bookmark' title='Randomly Display Some Images From A Set of Images: PHP'>Randomly Display Some Images From A Set of Images: PHP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>PHP program to store page views count in SESSION, to increment the count on each refresh, and to show the count on web page.</strong></p>
<p><strong>Session:</strong>  A session is specific to the user and for each user a new session is created to track all the request from that user. Every user has a separate session and separate session variable which is associated with that session.</p>
<p>The concept of session is more visible and practical when we explain building log in form using MySQL database. Until then, memorize the above definition!</p>
<p>In this PHP program, as the above question suggests: we are storing the page view count in a session variable and incrementing it on each page view. </p>
<p><strong>Mechanism used:</strong><br />On the first visit, the session variable is set to 1 and as this is the first visit, a message &#8220;Session does not exist&#8221; is displayed on the web page.<br />
As the session variable is set to 1 on first visit, on consecutive visits the code inside the <strong>if</strong> block is executed and the value of the session variable is echo&#8217;ed or printed on to the browser and then incremented by one.<br />
<br />
<strong>Video Tutorial:</strong><br />
<center><iframe title="YouTube video player" class="youtube-player" type="text/html" width="630" height="385" src="http://www.youtube.com/embed/VmB6ZrhLAp0?rel=0" frameborder="0" allowFullScreen></iframe></center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=VmB6ZrhLAp0">http://www.youtube.com/watch?v=VmB6ZrhLAp0</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /></p>
<p><strong>Complete Source Code:</strong>(session.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php 
	session_start();
&nbsp;
	if(isset($_SESSION['count']))
	{
		echo &quot;Your session count: &quot;.$_SESSION['count'].&quot;&lt;br /&gt;&quot;;
		$_SESSION['count']++;
	}
	else
	{
		$_SESSION['count'] = 1;
		echo &quot;Session does not exist&quot;;
	}
&nbsp;
?&gt;</pre></td></tr></table></div>

<p><strong>Code Explanation:</strong><br />
<strong>session_start()</strong> is a standard call and is mandatory step to start the session. On each page, wherever you use the session variable, you must write session_start() before using the session variable. It is a usual practice to write session_start(); as the first line of code in a php program whenever necessary.</p>
<p><strong>$_SESSION['sessionName']</strong> is a session variable. <strong>sessionName</strong> is the session name and it should be enclosed within single quote.</p>
<p><strong>isset()</strong> is a standard php function which returns true or false depending upon whether the passed parameter is set or not.</p>
<p>In all major programming languages(including PHP) we use shorthand notations like <strong>$_SESSION['count']++;</strong> which means <strong>$_SESSION['count'] = $_SESSION['count'] + 1;</strong> Here <strong>++</strong> is called increment operator. <br />
And in <strong>$_SESSION['count']- -;</strong> which is equal to writing <strong>$_SESSION['count'] = $_SESSION['count'] &#8211; 1;</strong> Here <strong>- -</strong> is called decrement operator.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/279/dynamic-page-creation-php/' rel='bookmark' title='Dynamic Page Creation: PHP'>Dynamic Page Creation: PHP</a></li>
<li><a href='http://technotip.com/231/return-multiple-values-function-arrays-php/' rel='bookmark' title='Return Multiple Values From Function Using Arrays In PHP'>Return Multiple Values From Function Using Arrays In PHP</a></li>
<li><a href='http://technotip.com/387/randomly-display-some-images-from-a-set-of-images-php/' rel='bookmark' title='Randomly Display Some Images From A Set of Images: PHP'>Randomly Display Some Images From A Set of Images: PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/402/store-page-view-count-in-session-variable-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Randomly Display Some Images From A Set of Images: PHP</title>
		<link>http://technotip.com/387/randomly-display-some-images-from-a-set-of-images-php/</link>
		<comments>http://technotip.com/387/randomly-display-some-images-from-a-set-of-images-php/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 14:36:08 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=387</guid>
		<description><![CDATA[Use of this script:1. If you have a photo blog with 100 or more images, using this small php script you can show some random images on your homepage, to keep it more dynamic.. This makes up for a good user experience due to constant fresh content(images) each time.2. If you have 10 products and [...]
Related posts:<ol>
<li><a href='http://technotip.com/231/return-multiple-values-function-arrays-php/' rel='bookmark' title='Return Multiple Values From Function Using Arrays In PHP'>Return Multiple Values From Function Using Arrays In PHP</a></li>
<li><a href='http://technotip.com/279/dynamic-page-creation-php/' rel='bookmark' title='Dynamic Page Creation: PHP'>Dynamic Page Creation: PHP</a></li>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>Use of this script:</strong><br /><strong>1.</strong> If you have a photo blog with 100 or more images, using this small php script you can show some random images on your homepage, to keep it more dynamic.. This makes up for a good user experience due to constant fresh content(images) each time.<br /><strong>2.</strong> If you have 10 products and you want to show atleast 3 products image on your homepage, using this php script you can randomly display the images and yet not bore your audience!</p>
<p>
<strong>Video Tutorial:</strong><br />
<center></p>
<p><object width="630" height="385"><param name="movie" value="http://www.youtube.com/v/ajAj6oAkz60?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ajAj6oAkz60?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="630" height="385"></embed></object><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=ajAj6oAkz60">http://www.youtube.com/watch?v=ajAj6oAkz60</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /></p>
<p><strong>Complete Source Code:</strong>(image.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
	$pic = array('1.jpg','2.jpg','3.jpg','4.jpg','5.jpg');
	shuffle($pic);
?&gt;
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Random Images&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;ul&gt;
	&lt;?php
	   for( $i = 0; $i &lt; 3; $i++)
	      echo &quot;&lt;li style=\&quot;display: inline;\&quot;&gt;
                         &lt;img src=\&quot;$pic[$i]\&quot; width=\&quot;250\&quot; height=\&quot;250\&quot;&gt;
                       &lt;/li&gt;&quot;;
&nbsp;
	?&gt;	
 &lt;/ul&gt;
&nbsp;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Copy and paste above code into a plain text editor. Save the file with .php file extension. Make sure to have 5 image files(with .jpg extensions) in the same folder as image.php</p>
<p><center><img src="http://technotip.com/wp-content/uploads/php/random-image.jpg" alt="random image Randomly Display Some Images From A Set of Images: PHP" width="393px" height="349px" title="Randomly Display Some Images From A Set of Images: PHP" /></center></p>
<p><br style="clear: both;" /></p>
<p><strong>PHP Code Explanation:</strong><br /> Arrays are very important concept in all programming language.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;"> $pic = array('1.jpg','2.jpg','3.jpg','4.jpg','5.jpg');</pre></div></div>

<p> here <strong>$pic</strong> is an array variable and is used to store the file names of all the images.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">shuffle($pic);</pre></div></div>

<p> <strong>shuffle()</strong> is a standard PHP function, which shuffles the content of the array variable. i.e., it re-orders or changes the position of the elements of an array.</p>
<p></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
	for( $i = 0; $i &lt; 3; $i++)
		echo &quot;&lt;li style=\&quot;display: inline;\&quot;&gt;
                           &lt;img src=\&quot;$pic[$i]\&quot; width=\&quot;250\&quot; height=\&quot;250\&quot;&gt;
                        &lt;/li&gt;&quot;;
?&gt;</pre></td></tr></table></div>

<p>Usually unordered listing tags of HTML displays elements vertically.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;li style=&quot;display: inline;&quot;&gt; &lt;/li&gt;</pre></div></div>

<p> But using some css style property, we are showing the images horizontally.<br />
i.e., display: inline;</p>
<p><strong>for loop</strong>, loops through 0 to 3(in above example). After the execution of the above line of code(for one instance), we get the following HTML output in the browser.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">  &lt;ul&gt;
	&lt;li style=&quot;display: inline;&quot;&gt;
            &lt;img src=&quot;4.jpg&quot; width=&quot;250&quot; height=&quot;250&quot;&gt;
       &lt;/li&gt;
       &lt;li style=&quot;display: inline;&quot;&gt;
           &lt;img src=&quot;5.jpg&quot; width=&quot;250&quot; height=&quot;250&quot;&gt;
       &lt;/li&gt;
       &lt;li style=&quot;display: inline;&quot;&gt;
            &lt;img src=&quot;1.jpg&quot; width=&quot;250&quot; height=&quot;250&quot;&gt;
       &lt;/li&gt;	
 &lt;/ul&gt;</pre></td></tr></table></div>

<p><strong>\</strong> (back slash) is used as an escape character, to escape the effect of <strong>&#8220;</strong> (double quote).</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/231/return-multiple-values-function-arrays-php/' rel='bookmark' title='Return Multiple Values From Function Using Arrays In PHP'>Return Multiple Values From Function Using Arrays In PHP</a></li>
<li><a href='http://technotip.com/279/dynamic-page-creation-php/' rel='bookmark' title='Dynamic Page Creation: PHP'>Dynamic Page Creation: PHP</a></li>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/387/randomly-display-some-images-from-a-set-of-images-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Page Creation: PHP</title>
		<link>http://technotip.com/279/dynamic-page-creation-php/</link>
		<comments>http://technotip.com/279/dynamic-page-creation-php/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 22:30:26 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dynamic page. parameter]]></category>
		<category><![CDATA[file_exists function]]></category>
		<category><![CDATA[file_exists()]]></category>
		<category><![CDATA[if-elseif-else Statement]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=279</guid>
		<description><![CDATA[In this PHP program we will not be generating pages, but creating the illusion of dynamic page creation! i.e., we will have a bunch of files inside a directory. We will fetch the contents of these files and display on a single file(index.php). Advantages: 1. Eliminating duplicate coding: Since, we will display the contents on [...]
Related posts:<ol>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
<li><a href='http://technotip.com/231/return-multiple-values-function-arrays-php/' rel='bookmark' title='Return Multiple Values From Function Using Arrays In PHP'>Return Multiple Values From Function Using Arrays In PHP</a></li>
<li><a href='http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/' rel='bookmark' title='PHP Comments, String Concatenation, Addition of Numbers &amp; Hello World'>PHP Comments, String Concatenation, Addition of Numbers &#038; Hello World</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this PHP program we will not be generating pages, but creating the illusion of dynamic page creation!<br />
i.e., we will have a bunch of files inside a directory. We will fetch the contents of these files and display on a single file(index.php).</p>
<p><strong>Advantages:</strong><br />
<strong>1.</strong> Eliminating duplicate coding: Since, we will display the contents on single page, all the common content will be written in that single page.<br />
<strong>2.</strong> Common user will not be able to track the exact location of the individual files.<br />
<strong>3.</strong> We can track, if the user is trying to access a file that does not exist, and then we can show appropriate messages: This will be user friendly and also helps in Search Engine Optimization(SEO), as we can specially design our 404 pages.</p>
<p><strong>Note:</strong> Even though this dynamic page creation may not be something you are looking for right now, I am sure, you will encounter a situation in your project development where this technique will come handy. So nevertheless, have it in your tool box!<br />
<br />
<center><br />
<object width="630" height="385"><param name="movie" value="http://www.youtube.com/v/RrSRO248NOQ?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RrSRO248NOQ?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="630" height="385"></embed></object><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=RrSRO248NOQ">http://www.youtube.com/watch?v=RrSRO248NOQ</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /></p>
<p><strong>PHP Program with CSS implemented:</strong> (index.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&nbsp;
&lt;html&gt;
 &lt;head&gt;&lt;title&gt; Dynamic Pages &lt;/title&gt;
&nbsp;
	&lt;style type=&quot;text/css&quot;&gt;
&nbsp;
		* {
			font-family: Verdana;
			font-size: 24pt;
&nbsp;
		}
		#menu {
			position: absolute;
			top: 50px;
			left: 200px;
&nbsp;
			padding: 10px;
			margin:  10px;
&nbsp;
			background-color: pink;
&nbsp;
		}	
&nbsp;
		#content {
			position: absolute;
			top: 50px;
			left: 450px;
&nbsp;
			padding: 10px;
			margin:  10px;
&nbsp;
			background-color: yellow;
			color: red;
&nbsp;
		}
&nbsp;
&nbsp;
	&lt;/style&gt;
 &lt;/head&gt;
 &lt;body&gt;
&nbsp;
  &lt;div id=&quot;menu&quot;&gt;
&nbsp;
	&lt;a href=&quot;index.php&quot;&gt;Home&lt;/a&gt;&lt;br /&gt;
	&lt;a href=&quot;index.php?page=js&quot;&gt;Javascript&lt;/a&gt;&lt;br /&gt;
	&lt;a href=&quot;index.php?page=cSharp&quot;&gt;C Sharp&lt;/a&gt;&lt;br /&gt;
	&lt;a href=&quot;index.php?page=css&quot;&gt;CSS&lt;/a&gt;&lt;br /&gt;
&nbsp;
  &lt;/div&gt;
&nbsp;
 &lt;div id=&quot;content&quot;&gt;
&nbsp;
	&lt;?php
 		$p = $_GET['page'];
&nbsp;
		$page = &quot;sub/&quot;.$p.&quot;.php&quot;;
&nbsp;
		if(file_exists($page))
			include($page);
		elseif($p==&quot;&quot;)
			echo &quot;This is Home Page&quot;;
		else
			echo &quot;what are you looking for! ?&quot;;
&nbsp;
	?&gt;
  &lt;/div&gt;
&nbsp;
&nbsp;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>In the <strong>menu div</strong>, we are having some anchor tags, using which we are passing the file names to the variable <strong>page</strong>. Which we receive in the php code(same page) and add the exact file location and check whether the file exists in the specified location or not.</p>
<p>Based on the file name passed, we will include the corresponding file content in the <strong>content div</strong> section. If nothing is passed,  then its home page. If some irrelevant file names are passed, then we will show some messages: Here we can design a 404 error message page and show it &#8211; each time someone tries to access a page that does not exists.</p>
<p><strong>File Structure:</strong><br />
<img src="http://technotip.com/wp-content/uploads/php/file-structure.jpg" alt="file structure Dynamic Page Creation: PHP" width="568" height="226" title="Dynamic Page Creation: PHP" /><br />
Save all these below files ( js.php, cSharp.php, css.php and index.php )  as shown in above image.</p>
<p><strong>js.php</strong> Content:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">This is Javascript File...</pre></div></div>

<p><strong>cSharp.php</strong> Content: </p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">This is C Sharp....</pre></div></div>

<p><strong>css.php</strong> Content:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">This is Cascading StyleSheet...</pre></div></div>

<p>
[ Above files are kept simple in-order to save time and to keep the program explanation simple. You can use your web designing skills to make the pages as you like. ]<br />
<br />
<strong>PHP Code Explanation:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">$p = $_GET['page'];</pre></div></div>

<p>This line of code accepts the parameter sent by the anchor tags and stores it in a variable by name <strong>p</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">		$page = &quot;sub/&quot;.$p.&quot;.php&quot;;</pre></div></div>

<p><strong>sub</strong> is the folder name, inside which we have our js.php, cSharp.php and css.php files.</p>
<p><strong>Ex:</strong><br />
If the link corresponding to <strong>cSharp</strong> is clicked. Then variable <strong>p</strong> will have the string <strong>cSharp</strong> in it.<br />
So, variable <strong>page</strong> will have <strong>sub/cSharp.php</strong> in it.</p>
<p><strong>if-elseif-else Statement:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">		if(file_exists($page))
			include($page);
		elseif($p==&quot;&quot;)
			echo &quot;This is Home Page&quot;;
		else
			echo &quot;what are you looking for! ?&quot;;</pre></div></div>

<p><strong>file_exists</strong> is a built-in php function, which checks if the specified page/file exists or not.<br />
If it exists, then we will include that page. i.e., the content of the page will be displayed.<br />
If variable <strong>p</strong> has nothing in it, then the clicked link is home page.<br />
If some non-existing page is passed, then we display the message &#8220;What are you looking for! ?&#8221;.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
<li><a href='http://technotip.com/231/return-multiple-values-function-arrays-php/' rel='bookmark' title='Return Multiple Values From Function Using Arrays In PHP'>Return Multiple Values From Function Using Arrays In PHP</a></li>
<li><a href='http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/' rel='bookmark' title='PHP Comments, String Concatenation, Addition of Numbers &amp; Hello World'>PHP Comments, String Concatenation, Addition of Numbers &#038; Hello World</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/279/dynamic-page-creation-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Return Multiple Values From Function Using Arrays In PHP</title>
		<link>http://technotip.com/231/return-multiple-values-function-arrays-php/</link>
		<comments>http://technotip.com/231/return-multiple-values-function-arrays-php/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 17:36:03 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[multiple values]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[print_r]]></category>
		<category><![CDATA[return]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=231</guid>
		<description><![CDATA[If you are a C/C++ programmer, then you know that functions can not return more than one value. To over come this, they use Call by Reference &#8211; where address of the variables is passed, hence whenever the value in the passed address changes, the value of the actual variable changes without anything being returned. [...]
Related posts:<ol>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
<li><a href='http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/' rel='bookmark' title='PHP Comments, String Concatenation, Addition of Numbers &amp; Hello World'>PHP Comments, String Concatenation, Addition of Numbers &#038; Hello World</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you are a C/C++ programmer, then you know that functions can not return more than one value. To over come this, they use Call by Reference &#8211; where address of the variables is passed, hence whenever the value in the passed address changes, the value of the actual variable changes without anything being returned.</p>
<p>In PHP we can accomplish this with the help of arrays.</p>
<p><strong>Video Explaining The PHP Code:</strong><br />
<center><br />
<object width="630" height="385"><param name="movie" value="http://www.youtube.com/v/HsX2ay702R8&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1&#038;ap=%2526fmt%3D22"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/HsX2ay702R8&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1&#038;ap=%2526fmt%3D22" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="630" height="385"></embed></object><br />
</center></p>
<div style="font-size: small;">YouTube Link: <a href="http://www.youtube.com/watch?v=HsX2ay702R8">http://www.youtube.com/watch?v=HsX2ay702R8</a> [Watch the Video In Full Screen.]</div>
<p><br style="clear: both;" /></p>
<p><strong>Work Flow:</strong> <br /> <strong>Step 1:</strong> Here we pass the values to the function.</p>
<p><strong>Step 2:</strong> Calculation or operation takes place inside the function. </p>
<p><strong>Step 3:</strong> In case there are multiple things to return, we store it inside a array variable. Ex: $result = array($add, $sub, $mul, $div);</p>
<p><strong>Step 4:</strong> We return the array variable.</p>
<p><strong>Step 5:</strong> Now using array index we display the individual result using echo or print statement.<br />
<br />
<strong>PHP program explained in above video:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
 &lt;head&gt;&lt;title&gt;Return Multiple Values From Functions, 
                                           using Arrays: In PHP&lt;/title&gt;&lt;/head&gt;
 &lt;body&gt;
&nbsp;
	&lt;?php
		$get_result = calc(20, 10);
&nbsp;
		echo &quot;Addition: &quot;.$get_result[0].&quot;&lt;br /&gt;Subtration :&quot;.$get_result[1].
			&quot;&lt;br /&gt;Multiplication: &quot;.$get_result[2].&quot;
                         &lt;br /&gt;Division: &quot;.$get_result[3];
		echo &quot;&lt;br /&gt;&lt;br /&gt;&quot;;
&nbsp;
		print_r ($get_result);
&nbsp;
	?&gt;
&nbsp;
	&lt;?php
		function calc($one, $two)
		{
			$add = $one + $two;
			$sub  =  $one  -  $two;
			$mul = $one * $two;
			$div  =  $one  / $two;
&nbsp;
			$result = array($add, $sub, $mul, $div);
&nbsp;
			return $result;
		}
	?&gt;
&nbsp;
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p><strong>Output:</strong><br />
Addition: 30<br />
Subtration :10<br />
Multiplication: 200<br />
Division: 2</p>
<p>Array ( [0] => 30 [1] => 10 [2] => 200 [3] => 2 )</p>
<p><strong>Things To Remember:</strong><br /> <strong>1.</strong> All PHP files must have .php file extension.</p>
<p><strong>2.</strong> Concatination operator in PHP is <strong>.</strong> [DOT]</p>
<p><strong>3.</strong> <strong>print_r</strong> is a  function which takes array variable as its argument and displays the input array structure. Ex: print_r ($get_result);</p>
<p><strong>4.</strong> Function is defined in php using the keyword <strong>function</strong>, followed by function name.</p>
<p><strong>5.</strong> $ is used to declare variables in PHP.<br />
<br />
<strong>Array Syntax In PHP:</strong><br />
$variable = array(arrayElements);<br />
<br />
<strong>For Numbers: Ex:</strong> $num = array(20, 40, 50, 60, 100);<br />
<strong>For Strings: Ex:</strong> $str = array(&#8220;Microsoft&#8221;,&#8221;Apple&#8221;,&#8221;Oracle&#8221;,&#8221;Google&#8221;);<br />
<strong>For Character: Ex:</strong> $chr = array(&#8216;A&#8217;,'E&#8217;,'I&#8217;,'O&#8217;,'U&#8217;);<br />
<br />
<strong>array</strong> is a keyword for declaring/initializing arrays in PHP.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
<li><a href='http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/' rel='bookmark' title='PHP Comments, String Concatenation, Addition of Numbers &amp; Hello World'>PHP Comments, String Concatenation, Addition of Numbers &#038; Hello World</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/231/return-multiple-values-function-arrays-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Comments, String Concatenation, Addition of Numbers &amp; Hello World</title>
		<link>http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/</link>
		<comments>http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 09:19:52 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[addition of numbers]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[program instructions programs]]></category>
		<category><![CDATA[string concatenation]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=76</guid>
		<description><![CDATA[Today lets see these 4 basic things:1. The classic &#8220;Hello World&#8221; program.2. Comment system in PHP.3. Concatenation of Strings.4. Addition of Numbers. Classic &#8220;Hello World&#8221; program Program to output simple string 1 2 3 &#60;?php echo &#34;Hello World&#34;; ?&#62; Comments: 1 // This is single line comment 1 # This is also a single line [...]
Related posts:<ol>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>Today lets see these 4 basic things:</strong><br /><strong>1.</strong> The classic &#8220;Hello World&#8221; program.<br /><strong>2.</strong> Comment system in PHP.<br /><strong>3.</strong> Concatenation of Strings.<br /><strong>4.</strong> Addition of Numbers.</p>
<p><center><br />
<object width="630" height="354"><param name="movie" value="http://www.youtube.com/v/e7ZPLiOon5I&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/e7ZPLiOon5I&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="630" height="354"></embed></object><br />
</center>
</p>
<p></p>
<p><strong>Classic &#8220;Hello World&#8221; program</strong><br /> Program to output simple string</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
          echo &quot;Hello World&quot;;
?&gt;</pre></td></tr></table></div>

<p><strong>Comments:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">// This is single line comment</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;"># This is also a single line comment</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">/* This is how multi-line comments
    are written.
*/</pre></td></tr></table></div>

<p>Anything following a double forward slash or a hash( # ) symbol will be ignored by your parser. Comments are very important and are often ignored by programmers. Comments come handy when we come back to the codes and want to make some changes to the coding. So its always a good practice to write comments wherever appropriate. </p>
<p><strong>Concatenation of Strings</strong><br />Concatination is joining of two or more strings end to end. Ex: if we concatenate <strong>Micro</strong> and <strong>soft</strong>, it will become <strong>Microsoft</strong>.<br />
In PHP, we use <strong>.</strong>[DOT] operator for concatenation. Below is an example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php 
         echo &quot;Micro&quot; . &quot;soft&quot;;
         echo &quot;&lt;br /&gt;Oracle, &quot; . &quot;Sun Microsystems&quot;;
?&gt;</pre></td></tr></table></div>

<p>The output for the above php code is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">Microsoft
Oracle, Sun Microsystems</pre></td></tr></table></div>

<p><strong>Addition of Numbers</strong><br /> We can use variables for addition of numbers or we can simply make use of echo or print for addition of numbers.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
         echo 10+20;
?&gt;</pre></td></tr></table></div>

<p>This gives 30 as the output.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?php
         echo &quot;5&quot;+10;
?&gt;</pre></td></tr></table></div>

<p>This gives 15 as output. The string &#8220;5&#8243; will be implicitly converted into number and will be added to the actual number 10.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/59/first-php-program-worst-practices-avoid/' rel='bookmark' title='First PHP program &amp; Worst Practices To Avoid'>First PHP program &#038; Worst Practices To Avoid</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/76/php-comments-string-concatenation-addition-of-numbers-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First PHP program &amp; Worst Practices To Avoid</title>
		<link>http://technotip.com/59/first-php-program-worst-practices-avoid/</link>
		<comments>http://technotip.com/59/first-php-program-worst-practices-avoid/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 02:30:59 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[avoid]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[better programmer]]></category>
		<category><![CDATA[first program]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpinfo]]></category>
		<category><![CDATA[practice]]></category>
		<category><![CDATA[worst practices]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=59</guid>
		<description><![CDATA[We can embed php inside html tags and html tags inside php codes, but whatever it is &#8211; your php file name must end with a .php extension, so that the parser can identify that the file contains php code and it must also look for &#60;?php and ?&#62; codes inorder to recognise the codes [...]
Related posts:<ol>
<li><a href='http://technotip.com/50/accessing-localhost-web-server-mac-pc/' rel='bookmark' title='Accessing localhost Web-server on Mac and PC'>Accessing localhost Web-server on Mac and PC</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>We can embed php inside html tags and html tags inside php codes, but whatever it is &#8211; your php file name must end with a .php extension, so that the parser can identify that the file contains php code and it must also look for</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;?php and ?&gt;</pre></div></div>

<p> codes inorder to recognise the codes as PHP codes and execute them.</p>
<p><strong>Note:</strong> The output of PHP code is html.</p>
<p><strong>Some Worst Practices to avoid:</strong><br />Some people may use</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;? 
    some_php_codes(); 
?&gt;</pre></div></div>

<p>OR</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;?= 
    some_php_codes(); 
?&gt;</pre></div></div>

<p>OR <strong>ASP</strong> style( <strong>A</strong>ctive <strong>S</strong>erver <strong>P</strong>ages &#8211; from Microsoft Inc )</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;% 
    some_php_codes(); 
%&gt;</pre></div></div>

<p>OR</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;%= 
    some_php_codes(); 
%&gt;</pre></div></div>

<p>and whole lot of other things.</p>
<p>All these or atleast some of these styles may even work on your computer, and that&#8217;s because of the way your php.ini file is configured.  The same file may not work on other web servers.<br />
So the best practice is to stick with using</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;?php 
    your_php_code; 
?&gt;</pre></div></div>

<p>Also note that, white space isn&#8217;t significant in PHP. i.e., you can introduce any number of spaces, tabs, and new line characters in between your PHP codes.<br />
But there must be atleast a single space after</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;?php</pre></div></div>

<p>
<center><br />
<object width="630" height="354"><param name="movie" value="http://www.youtube.com/v/lZNrF9Y2suE&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/lZNrF9Y2suE&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="630" height="354"></embed></object><br />
</center>
</p>
<p><strong>Our First PHP program:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">&lt;?php
          phpinfo();
?&gt;</pre></div></div>

<p>Make sure you have saved the file with ( filename.php ) .php extension. Now open the saved file in your web browser.<br />
If your server is working, then you must see a screen that gives information about your web server and PHP.<br />
<strong>Output Screenshot:</strong><br />
<img src="http://technotip.com/wp-content/uploads/php/phpinfo.png" alt="phpinfo First PHP program & Worst Practices To Avoid" width="590" height="387" title="First PHP program & Worst Practices To Avoid" /></p>
<p>Don&#8217;t make this file available on your server for general public, as it gives a lot of information about your server. Its a handy tool to quickly scan your server configuration.</p>
<p>Related posts:<ol>
<li><a href='http://technotip.com/50/accessing-localhost-web-server-mac-pc/' rel='bookmark' title='Accessing localhost Web-server on Mac and PC'>Accessing localhost Web-server on Mac and PC</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/59/first-php-program-worst-practices-avoid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing localhost Web-server on Mac and PC</title>
		<link>http://technotip.com/50/accessing-localhost-web-server-mac-pc/</link>
		<comments>http://technotip.com/50/accessing-localhost-web-server-mac-pc/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 13:23:38 +0000</pubDate>
		<dc:creator>Satish</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[accessing]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[pc]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web files]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://technotip.com/?p=50</guid>
		<description><![CDATA[Make sure that you turn on the Wamp if you are on a PC and Mamp if you are on Mac. PC users can access their web files using the URL http://localhost/ Mac users can access their web files using the URL http://localhost/~yourUserDirectory yourUserDirectory is the user account name of your Mac computer using which [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Make sure that you turn on the Wamp if you are on a PC and Mamp if you are on Mac.</p>
<p>PC users can access their web files using the URL http://localhost/</p>
<p>Mac users can access their web files using the URL http://localhost/~yourUserDirectory</p>
<p>yourUserDirectory is the user account name of your Mac computer using which you have logged in.</p>
<p>On my Mac, I have a user directory by name Satish. So I can access my web files using http://localhost/~Satish</p>
<p>On Mac, once you enter http://localhost/~yourUserDirectory  it automatically changes the URL &#8211; but don&#8217;t worry about it, its working fine and that&#8217;s how it works!</p>
<p>
<center><br />
<object width="630" height="354"><param name="movie" value="http://www.youtube.com/v/KKxxpnRvxx4&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/KKxxpnRvxx4&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="630" height="354"></embed></object><br />
</center>
</p>
<p></p>
<p>Let non of these small things make you not use the web server. I am writing this because, some times small things like this suck a lot of time and some people may even start feeling this as something very much technical and complicated and may leave the idea of learning altogether.</p>
<p>If you successfully accessed your web files from your localhost web server, then congratulations. Continue your exploration. We have a lot of simple PHP examples on this website that you may want to try. All the Best.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://technotip.com/50/accessing-localhost-web-server-mac-pc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

