<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>The Web Hosting Blog &#187; Programming</title>
	<atom:link href="http://blog.readysetconnect.com/category/web-master-tutorials/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.readysetconnect.com</link>
	<description>An inside look into ReadySetConnect and the Web Hosting industry</description>
	<lastBuildDate>Mon, 30 Mar 2009 22:51:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Importance of Scripting Languages &#8211; Sample PHP Tutorials</title>
		<link>http://blog.readysetconnect.com/2009/02/the-importance-of-scripting-languages-sample-php-tutorials/</link>
		<comments>http://blog.readysetconnect.com/2009/02/the-importance-of-scripting-languages-sample-php-tutorials/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 22:38:24 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Master Tutorials]]></category>
		<category><![CDATA[programming tutorials]]></category>
		<category><![CDATA[scripting languages]]></category>
		<category><![CDATA[website scripts]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=402</guid>
		<description><![CDATA[Whether you spend your day working fulltime as a web server administrator, or you like to host a simple website on a spare computer in your basement, one of the best ways to increase your productivity and develop very useful tools is to write programs called scripts. Scripts are normally short, high-level computer programs that [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Whether you spend your day working fulltime as a web server administrator, <a href="http://blog.readysetconnect.com/2009/02/hosting-your-website-off-your-home-pc-is-a-personal-web-server-a-good-idea/">or you like to host a simple website on a spare computer in your basement</a>, one of the best ways to increase your productivity and develop very useful tools is to write programs called scripts. Scripts are normally short, high-level computer programs that are easy to write and let you accomplish a wide range of objectives, from automating tedious tasks to increasing interaction between different programs on your computer.</p>
<p>Determining the best scripting language for you may depend on what languages are available on your given system. Some languages are very easy and let you accomplish many things with one line of code, whereas others are more verbose, yet more powerful. The language you choose is entirely up to you, and I recommend exploring several different languages before you start to dig in on one.</p>
<p>Over the next few weeks we’re going to cover many tutorials on different types of scripts you can write. We’ll provide the sample code in different languages like PHP and Ruby, so you can get a good idea on how each language works. Below are a few, short scripts written in PHP that let you easily add some cool functionality to your website. If your server or computer has PHP functionality, simply copy this code into a file with a &#8220;.php&#8221; extension to test it out!</p>
<p><strong>Add a Random Quote to Your Website</strong></p>
<p>This sample code will read in a random quote from iheartquotes.com, and print that quote on your website. To change the type of quote, go to http://www.iheartquotes.com and select a category name. Update the section of the code that reads $src = &#8220;albert_enstein&#8221;; by replacing albert_einstein with your new category, and then updating the line that reads &#8220;A random quote from Albert Einstein&lt;br&gt;&lt;br&gt;&#8221;; with your category’s name.</p>
<pre>&lt;?php
$src = "albert_einstein";
echo "A random quote from Albert Einstein: &lt;br&gt;&lt;br&gt;";
echo nl2br(file_get_contents("http://www.iheartquotes.com/api/v1/random?source=$src"));
?&gt;</pre>
<p><strong>Quickly Count the Lines of a File</strong></p>
<p>This sample code will read a file and count the number of lines. This code works with text files on your computer, or with web pages. Simply change the Web Hosting Blog address to point to either a text file on the internet or on your computer.</p>
<pre>&lt;?php
$file = "http://blog.readysetconnect.com";
echo "The number of lines in the file is: " . sizeof(explode("\n", file_get_contents($file)));
?&gt;</pre>
<p>Although short, these two scripts show how easy it can be to add a lot of functionality to your set of tools with relatively little code. We will post in-depth code samples in the coming weeks.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2009/02/the-importance-of-scripting-languages-sample-php-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up the logout functions to clear the user session ID</title>
		<link>http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/</link>
		<comments>http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 00:31:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[login script]]></category>
		<category><![CDATA[logout]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=182</guid>
		<description><![CDATA[
PHP &#38; MySQL Login Tutorial Series
Pt1: Introduction
Pt2: Setting up the database
Pt3: The front end and user validation
Pt4: The code to privatize a page
Pt5: Logout function and clearing the session ID
Part 5: Logout functions
Our final function is the logout function that will wipe our session. That function is simpler and looks like this:
&#60;?php
function logout() {
$sessionid =$_COOKIE[test_account];
@setcookie [...]


Related posts:<ol><li><a href='http://blog.readysetconnect.com/2008/09/how-can-a-blog-help-your-main-website-setting-up-a-blog-to-increase-web-traffic/' rel='bookmark' title='Permanent Link: How can a blog help your main website? Setting up a blog to increase web traffic.'>How can a blog help your main website? Setting up a blog to increase web traffic.</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="login" src="http://blog.readysetconnect.com/login.jpg" alt="" width="225" height="188" /></p>
<p><strong>PHP &amp; MySQL Login Tutorial Series</strong><br />
Pt1: <a href="http://blog.readysetconnect.com/2008/10/simple-phpmysql-user-login-tutorial-make-parts-of-your-website-private-with-a-login/">Introduction</a><br />
Pt2: <a href="http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/">Setting up the database</a><br />
Pt3: <a href="http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/">The front end and user validation</a><br />
Pt4: <a href="http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/">The code to privatize a page</a><br />
Pt5: <a href="http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/">Logout function and clearing the session ID</a></p>
<h2>Part 5: Logout functions</h2>
<p>Our final function is the logout function that will wipe our session. That function is simpler and looks like this:</p>
<blockquote><p>&lt;?php<br />
function logout() {<br />
$sessionid =$_COOKIE[test_account];<br />
@setcookie (&#8221;test_account,&#8221;,time()-99999, &#8216;/&#8217;, &#8221;);<br />
mysql_query(&#8221;DELETE FROM user_sessions WHERE sessionid=&#8217;$sessionid&#8217;&#8221;);<br />
}<br />
?&gt;</p></blockquote>
<p>We first grab any session id out of the user&#8217;s submitted cookie. We then delete the cookie on the user&#8217;s computer by setting the cookie expiration date to sometime in the past (effectively deleting it), and we finally delete the session record from our database.</p>
<p>Before we can finish off the program we have two more tasks. The first is to throw an error message if the user enters invalid login credentials, and the second is to print out a greeting to the user if they&#8217;re logged in. Replace the HTML code from before with the following:</p>
<blockquote><p>&lt;?php<br />
if($userid &gt; 0) { echo &#8220;Welcome to our site, user #$userid (&lt;a href=&#8217;?logout&#8217;&gt;Click here to logout&lt;/a&gt;)&#8221;; } else {<br />
if($login_status != &#8221; &amp;&amp; $login_status == 0) { echo &#8220;Invalid username/password combo.&lt;br&gt;&#8221;; }<br />
?&gt;<br />
&lt;form action=&#8221;sample.php&#8221; method=&#8221;POST&#8221;&gt;<br />
&lt;input type=text name=username&gt;<br />
&lt;input type=password name=password&gt;<br />
&lt;input type=submit value=&#8221;Log In&#8221;&gt;<br />
&lt;/form&gt;<br />
&lt;?php } ?&gt;</p></blockquote>
<p>We first to check to see if our status function call returned a user id. If it did we can print out a welcome to the user, giving them his or her user id. We also provide a link for logging out; simply call the same page with &#8220;logout&#8221; specified as a URL GET variable to log out. If we don&#8217;t have a user id, we&#8217;ll print out the login form. We also check the login_status variable to see if there was an error. If there was we&#8217;ll print this out to the user.</p>
<p>This tutorial covers the basic concepts of a user login system, however it certainly doesn&#8217;t cover everything. There are many websites on the internet that can assist you with the specifics of setting up a database table, basic programming concepts, and anything in between. The full sample program can be <a title="found here" href="http://blog.readysetconnect.com/sample.php.txt">found here</a>. Note: In our example we assume you already have a connection to the database established, however sample.php includes the basic MySQL database connection functions.</p>


<p>Related posts:<ol><li><a href='http://blog.readysetconnect.com/2008/09/how-can-a-blog-help-your-main-website-setting-up-a-blog-to-increase-web-traffic/' rel='bookmark' title='Permanent Link: How can a blog help your main website? Setting up a blog to increase web traffic.'>How can a blog help your main website? Setting up a blog to increase web traffic.</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The validation code for the pages you want private.</title>
		<link>http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/</link>
		<comments>http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 00:30:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[login script]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=180</guid>
		<description><![CDATA[
PHP &#38; MySQL Login Tutorial Series
Pt1: Introduction
Pt2: Setting up the database
Pt3: The front end and user validation
Pt4: The code to privatize a page
Pt5: Logout function and clearing the session ID
Part 4: Privatizing your pages
Now let&#8217;s look at the status function. This function will be called on every page we want to protect. It will check [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="login" src="http://blog.readysetconnect.com/login.jpg" alt="" width="225" height="188" /></p>
<p><strong>PHP &amp; MySQL Login Tutorial Series</strong><br />
Pt1: <a href="http://blog.readysetconnect.com/2008/10/simple-phpmysql-user-login-tutorial-make-parts-of-your-website-private-with-a-login/">Introduction</a><br />
Pt2: <a href="http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/">Setting up the database</a><br />
Pt3: <a href="http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/">The front end and user validation</a><br />
Pt4: <a href="http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/">The code to privatize a page</a><br />
Pt5: <a href="http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/">Logout function and clearing the session ID</a></p>
<h2>Part 4: Privatizing your pages</h2>
<p>Now let&#8217;s look at the status function. This function will be called on every page we want to protect. It will check to see if the user has an active cookie, and will match the session id in the cookie to our session table. If there is a match, the user will be logged in. The function looks like this:</p>
<blockquote><p>&lt;?php<br />
function status() {<br />
$sessionid = $_COOKIE[test_account];<br />
$oldtime = $time() &#8211; 3600;<br />
$query = mysql_query(&#8221;SELECT * FROM user_sessions WHERE sessionid=&#8217;$sessionid&#8217; AND  timestamp&gt;$oldtime&#8221;);<br />
if(mysql_num_rows($query) == 1) {<br />
$info = mysql_fetch_array($query);<br />
return $info[userid];<br />
}<br />
return 0;<br />
}<br />
?&gt;</p></blockquote>
<p>First we&#8217;ll grab the session id that&#8217;s stored in the cookie &#8220;test_account.&#8221; The variable $oldtime is the oldest time the cookie could have been created. In this case that&#8217;s any time over the previous hour. The 3600 seconds must match the number of seconds in the setcookie function. We then query the session table for a match. If we find one we can pull the userid out of the session table and we&#8217;re logged in. Otherwise we return a 0.</p>
<p>Depending on your type of site, you may want to store frequently-used information in the session table for easy access. In this case, should we want to pull down the user&#8217;s username, we could use the userid pulled from the session table and then query the user_accounts table and match the user id for the account in question.</p>
<p><a class="alignright" href="http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/">Next -&gt; The Logout functions</a></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The frontend form and the PHP user login validation script</title>
		<link>http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/</link>
		<comments>http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 00:30:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[login script]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=178</guid>
		<description><![CDATA[
PHP &#38; MySQL Login Tutorial Series
Pt1: Introduction
Pt2: Setting up the database
Pt3: The front end and user validation
Pt4: The code to privatize a page
Pt5: Logout function and clearing the session ID
Part 3: Frontend form and validation
In this example we&#8217;re going to have a simple page that will display username and password text fields if a user [...]


Related posts:<ol><li><a href='http://blog.readysetconnect.com/2008/07/web-hosting-the-last-form-of-free-speech-in-america/' rel='bookmark' title='Permanent Link: Web hosting &#8211; the last form of free speech in America?'>Web hosting &#8211; the last form of free speech in America?</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="login" src="http://blog.readysetconnect.com/login.jpg" alt="" width="225" height="188" /></p>
<p><strong>PHP &amp; MySQL Login Tutorial Series</strong><br />
Pt1: <a href="http://blog.readysetconnect.com/2008/10/simple-phpmysql-user-login-tutorial-make-parts-of-your-website-private-with-a-login/">Introduction</a><br />
Pt2: <a href="http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/">Setting up the database</a><br />
Pt3: <a href="http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/">The front end and user validation</a><br />
Pt4: <a href="http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/">The code to privatize a page</a><br />
Pt5: <a href="http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/">Logout function and clearing the session ID</a></p>
<h2>Part 3: Frontend form and validation</h2>
<p>In this example we&#8217;re going to have a simple page that will display username and password text fields if a user is not logged in, and a simple greeting if the user is logged in. The HTML form code for the user/pass login should look something like this:</p>
<blockquote><p>&lt;form action=&#8221;sample.php&#8221; method=&#8221;POST&#8221;&gt;<br />
&lt;input type=text name=username&gt;<br />
&lt;input type=password name=password&gt;<br />
&lt;input type=submit value=&#8221;Log In&#8221;&gt;<br />
&lt;/form&gt;</p></blockquote>
<p>This HTML will give us a simple form with two fields named username and password. When a user enters the login info and clicks the submit button, the page will reload. Now we need to add in the PHP to retrieve these credentials when the page is loaded. To make sure everything works, add all of the PHP code to the top of the document (as seen in <a title="sample.php" href="http://blog.readysetconnect.com/sample.php.txt">sample.php</a>). To simplify the tutorial we&#8217;re going to give you the code for logging in, logging out, and checking user status in one snippet, however we will not be discussing all of it just yet. Here is the code that will regulate the user activity:</p>
<blockquote><p>&lt;?php<br />
if($_POST[username] !=&#8221; || $_POST[password] != &#8221;) {<br />
$login_status = login($_POST[username], $_POST[password]);<br />
} else if($_GET[logout]) {<br />
logout();<br />
}<br />
$userid = status();<br />
?&gt;</p></blockquote>
<p>Note: The above code must appear before any output in your document. If there is ANY output prior to this code being executed, you will receive errors when cookies are trying to be set during login.</p>
<p>We first check to see if the user is logging in, in which case we&#8217;ll call the login function, and we&#8217;ll also check to see if they&#8217;re logging out, in which case we will log out the current account. Finally we check to see the user&#8217;s status. If the user is logged in the userid will equal the user id. Otherwise it is equal to 0. Now let&#8217;s look at the functions we call in the above code.</p>
<p>The first function we&#8217;ll check is the login function. This is the meat of the program that will check user credentials. The code looks like this:</p>
<blockquote><p>&lt;?php<br />
function login($username, $password) {<br />
$username = addslashes($username);<br />
$password = md5($password);<br />
$query = mysql_query(&#8221;SELECT * FROM user_accounts WHERE username=&#8217;$username&#8217; AND password=&#8217;$password&#8217;&#8221;);<br />
if(mysql_num_rows($query) == 1) {<br />
$info = mysql_fetch_array($query);<br />
$userid = $info[userid];<br />
$sessionid = md5($userid . time());<br />
$time = time();<br />
@setcookie (&#8217;test_account&#8217;, $sessionid, $time+3600, &#8216;/&#8217;, &#8221;);<br />
mysql_query(&#8221;DELETE FROM user_sessions WHERE userid=&#8217;$userid&#8217;&#8221;);<br />
mysql_query(&#8221;INSERT INTO user_sessions (sessionid,userid,timestamp) VALUES(&#8217;$sessionid&#8217;,'$userid&#8217;,'$time&#8217;)&#8221;);<br />
return $userid;<br />
} else {<br />
return 0;<br />
}<br />
}<br />
?&gt;</p></blockquote>
<p>We begin by reading in the username and password. We used addslashes() to help protect against SQL injection attacks. Generally you wouldn&#8217;t have single quotes in usernames, however if someone tries to break into the system this will help protect you. Next we encrypt the password with MD5. MD5 is a hashing algorithm that will scramble any text and return a 32-character string. Whenever you add a user to the database, make sure the password is saved as a 32-character MD5 string. This will guarantee that anyone who may break into your database will not be able to steal your users&#8217; passwords. Again while this is not foolproof, it does help protect user data. The idea is that instead of matching two visible passwords, it&#8217;s better to match a scrambled password with the real password&#8217;s scrambled counterpart. Since MD5 will always return the same 32-character string for a specific input, we can guarantee that the MD5 hash stored in the database will always match the MD5 hash of the correct password. If you do not wish to encrypt your passwords, simply remove this line from the login function.</p>
<p>We then check the database to see if a user exists with the entered username/password combo. If a user does not exist we&#8217;ll return the integer 0. This is arbitrary, however the number must remain consistent throughout your program. If the user does exist, we&#8217;ll fetch the user id number. We then create a session id (again with md5). Note that we&#8217;re not only encrypting the user id as the session id, but we&#8217;re also concatenating the current timestamp to the user id. This will make it near-impossible for a would-be hacker to guess an active session id. You can use other salts to protect the session id even more.</p>
<p>After we have our session id we will want to store it on the user&#8217;s computer. To do this we call the setcookie() function. The first parameter, &#8220;test_account,&#8221; is simply the name of the cookie. Again you can set this to be whatever you want, however it must remain consistent throughout your code. The second parameter is our cookie contents, in this case the session id. It&#8217;s important that we only store non-identifiable information in the cookie. If we were to store something such as the user id or a username, it would be very easy for the would-be hacker to spoof the cookie and gain access to your user accounts. By using a session id, the hacker has to know the id in order to spoof; with our MD5 encryption this becomes difficult and makes it harder for the hacker to exploit your script. The third parameter is the cookie expiration time. $time+3600 is the current time plus 3600 seconds, or one hour in the future. Finally we set the directory the cookie is valid for. It&#8217;s sufficient to leave this parameter set to &#8220;/&#8221;.</p>
<p>After we set the cookie we need to clear out the session table. First we will want to wipe any old sessions for our user. We then insert the new session so we have something to match the cookie against whenever the user returns to our site.</p>
<p><a class="alignright" href="http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/">Next -&gt; Privatizing a page on your website</a></p>


<p>Related posts:<ol><li><a href='http://blog.readysetconnect.com/2008/07/web-hosting-the-last-form-of-free-speech-in-america/' rel='bookmark' title='Permanent Link: Web hosting &#8211; the last form of free speech in America?'>Web hosting &#8211; the last form of free speech in America?</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating the database for your PHP &amp; MySQL login script</title>
		<link>http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/</link>
		<comments>http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 00:28:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[login script]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=176</guid>
		<description><![CDATA[
PHP &#38; MySQL Login Tutorial Series
Pt1: Introduction
Pt2: Setting up the database
Pt3: The front end and user validation
Pt4: The code to privatize a page
Pt5: Logout function and clearing the session ID
Part 2: Creating the MySQL database
Before we get to programming, let&#8217;s setup the databases. You will need to create two different tables—one for user accounts and [...]


Related posts:<ol><li><a href='http://blog.readysetconnect.com/2009/03/creating-an-internet-marketing-plan-for-your-website-and-business/' rel='bookmark' title='Permanent Link: Creating an internet marketing plan for your website and business.'>Creating an internet marketing plan for your website and business.</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="login" src="http://blog.readysetconnect.com/login.jpg" alt="" width="225" height="188" /></p>
<p><strong>PHP &amp; MySQL Login Tutorial Series</strong><br />
Pt1: <a href="http://blog.readysetconnect.com/2008/10/simple-phpmysql-user-login-tutorial-make-parts-of-your-website-private-with-a-login/">Introduction</a><br />
Pt2: <a href="http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/">Setting up the database</a><br />
Pt3: <a href="http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/">The front end and user validation</a><br />
Pt4: <a href="http://blog.readysetconnect.com/2008/10/the-validation-code-for-the-pages-you-want-private/">The code to privatize a page</a><br />
Pt5: <a href="http://blog.readysetconnect.com/2008/10/setting-up-the-logout-functions-to-clear-the-user-session-id/">Logout function and clearing the session ID</a></p>
<h2>Part 2: Creating the MySQL database</h2>
<p>Before we get to programming, let&#8217;s setup the databases. You will need to create two different tables—one for user accounts and the other for sessions. Setup the tables as follows:</p>
<p>Table name: user_accounts<br />
Field 1: userid, int(10), primary key, auto_increment<br />
Field 2: username, varchar(10)<br />
Field 3: password, varchar(32)</p>
<p>Field 1 will store our user id number and will be a primary key for unique user identification. Field 2 is our username with a maximum of 10 characters. The number of characters can be set at whatever you&#8217;d like. Field 3 is our password field and, for this example, needs to be a minimum of 32 characters. You can use a larger size, however all passwords will be 32 characters in length.</p>
<p>Table name: user_sessions<br />
Field 1: sessionid, varchar(32), primary key<br />
Field 2: userid, int(10)<br />
Field 3: timestamp, int(12)</p>
<p>Field 1 will store our temporary session id and must be 32 characters as well as a primary key. Field 2 is our user id and its size must be equal to the size you selected in the user_accounts table. Field 3 is our time field. There are several ways to store a time in a database, however we will be storing the Unix timestamp.</p>
<p><a class="alignright" href="http://blog.readysetconnect.com/2008/10/the-frontend-form-and-the-php-user-login-validation-script/">Next -&gt; Front end + User validation</a></p>


<p>Related posts:<ol><li><a href='http://blog.readysetconnect.com/2009/03/creating-an-internet-marketing-plan-for-your-website-and-business/' rel='bookmark' title='Permanent Link: Creating an internet marketing plan for your website and business.'>Creating an internet marketing plan for your website and business.</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/10/creating-the-database-for-your-php-mysql-login-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>30 Free web designs and web templates &#8211; .PSD and HTML included</title>
		<link>http://blog.readysetconnect.com/2008/05/30-free-web-designs-and-web-templates-psd-and-html-included/</link>
		<comments>http://blog.readysetconnect.com/2008/05/30-free-web-designs-and-web-templates-psd-and-html-included/#comments</comments>
		<pubDate>Fri, 30 May 2008 23:56:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Master Tutorials]]></category>
		<category><![CDATA[free psd]]></category>
		<category><![CDATA[free web templates]]></category>
		<category><![CDATA[psd templates]]></category>
		<category><![CDATA[web design templates]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=20</guid>
		<description><![CDATA[We have a nice little free download for everyone out there.  We are providing for FREE, to anyone who wishes to use them, 30 pre-made web templates and web designs. These are all professional looking templates that we were planning to use in the site builder we were working on however we no longer [...]


Related posts:<ol><li><a href='http://blog.readysetconnect.com/2008/09/an-easy-way-to-build-a-website-using-wordpress-and-pre-designed-templates-for-a-quick-and-good-looking-website/' rel='bookmark' title='Permanent Link: An easy way to build a website. Using a WordPress installation and pre designed templates for a quick and good looking website.'>An easy way to build a website. Using a WordPress installation and pre designed templates for a quick and good looking website.</a></li><li><a href='http://blog.readysetconnect.com/2009/02/free-reseller-hosting-plans-and-free-dedicated-server-requests-come-on-now/' rel='bookmark' title='Permanent Link: LOL @ Free reseller hosting plans and free dedicated server requests'>LOL @ Free reseller hosting plans and free dedicated server requests</a></li><li><a href='http://blog.readysetconnect.com/2008/08/free-backlink-building-methods-build-free-back-links-for-better-search-engine-rankings/' rel='bookmark' title='Permanent Link: Free Backlink building methods. Build free back links for better search engine rankings.'>Free Backlink building methods. Build free back links for better search engine rankings.</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>We have a nice little free download for everyone out there.  We are providing for FREE, to anyone who wishes to use them, <a href="http://www.readysetconnect.com/free-templates.html">30 pre-made web templates and web designs</a>. These are all professional looking templates that we were planning to use in the site builder we were working on however we no longer have any use for them. Another company came up with a site builder software that was much better suited (and a heck of a lot cheaper) than ours. Each one of these designs cost me anywhere from $40-$150 so enjoy these templates on me. Each template download includes the full HTML for the design, all the images and .PSDs so that you can edit them. The only thing we ask is that you don&#8217;t hotlink anyone to the direct template download. Link them to the page below that has all the templates displayed. If you would like to provide a link directly back to www.readysetconnect.com, please feel free to do so <img src='http://blog.readysetconnect.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You may view a complete list and screen shots of the templates here:<a href="http://www.readysetconnect.com/free-templates.html"></a></p>
<p><a href="http://www.readysetconnect.com/free-templates.html">http://www.readysetconnect.com/free-templates.html</a></p>
<p>Enjoy,</p>
<p><a href="http://readysetconnect.com">ReadySetConnect Web Hosting</a></p>


<p>Related posts:<ol><li><a href='http://blog.readysetconnect.com/2008/09/an-easy-way-to-build-a-website-using-wordpress-and-pre-designed-templates-for-a-quick-and-good-looking-website/' rel='bookmark' title='Permanent Link: An easy way to build a website. Using a WordPress installation and pre designed templates for a quick and good looking website.'>An easy way to build a website. Using a WordPress installation and pre designed templates for a quick and good looking website.</a></li><li><a href='http://blog.readysetconnect.com/2009/02/free-reseller-hosting-plans-and-free-dedicated-server-requests-come-on-now/' rel='bookmark' title='Permanent Link: LOL @ Free reseller hosting plans and free dedicated server requests'>LOL @ Free reseller hosting plans and free dedicated server requests</a></li><li><a href='http://blog.readysetconnect.com/2008/08/free-backlink-building-methods-build-free-back-links-for-better-search-engine-rankings/' rel='bookmark' title='Permanent Link: Free Backlink building methods. Build free back links for better search engine rankings.'>Free Backlink building methods. Build free back links for better search engine rankings.</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/05/30-free-web-designs-and-web-templates-psd-and-html-included/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial #3 &#8211; IF Statements</title>
		<link>http://blog.readysetconnect.com/2008/05/php-tutorial-if-statements/</link>
		<comments>http://blog.readysetconnect.com/2008/05/php-tutorial-if-statements/#comments</comments>
		<pubDate>Sun, 18 May 2008 07:55:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[how to program in PHP]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php if statements]]></category>
		<category><![CDATA[php programming]]></category>
		<category><![CDATA[php tutorials]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=16</guid>
		<description><![CDATA[PHP Tutorial #3 &#8211; IF Statements
In order to make a successful PHP website, it is crucial to know how to correctly use if statements. IF statements, similar to CASE, have many advantages. Before we go further into these handy tools, let&#8217;s examine what they can do.
The IF statement allows you to control different parts of [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>PHP Tutorial #3 &#8211; IF Statements</p>
<p>In order to make a successful PHP website, it is crucial to know how to correctly use if statements. IF statements, similar to CASE, have many advantages. Before we go further into these handy tools, let&#8217;s examine what they can do.</p>
<p>The IF statement allows you to control different parts of your code based on input. An example when this would be used is if you have a menu that limits access based on different permissions. Look at the menu below:</p>
<p>Home<br />
Links<br />
Your Profile<br />
Post News<br />
Register an Account</p>
<p>With this particular menu, you would want everyone to have access to the &#8220;Home&#8221; and &#8220;Links&#8221; options. However, if a user comes on they do not have an account you would want them to see the &#8220;Register an Account&#8221; option. The &#8220;Your Profile&#8221; and &#8220;Post News&#8221; options would not be available. Now let&#8217;s say that person creates an account. You would want them to be able to access the &#8220;Your Profile&#8221; option, but you would not want them to &#8220;Post News&#8221; or register another account. As a last scenario, let&#8217;s say you log in. You would want to have access to the first four options. However, since you already have an account, there is no need for you to see the last option.</p>
<p>The use of IF statements allows us to control these options. There are several forms of IF that we can use.</p>
<p>IF &#8211; If there is a certain situation, execute this code.<br />
ELSE &#8211; If the IF statement returns FALSE, execute this code.<br />
ELSE IF &#8211; If the IF statement returns FALSE but you want to have additional options, continue with this.</p>
<p>The ELSE IF is a tricky to understand so I will go over that more in a second. Now let&#8217;s view the syntax. To make this simple, I will start with a basic IF statement.</p>
<p>In this situation I will check to see if a number is greater than another number.</p>
<p>$1 = 1;</p>
<p>if($1 &gt; 5) {</p>
<p>echo &#8220;$1 is greater than 5&#8243;;</p>
<p>}</p>
<p>else {</p>
<p>echo &#8220;$1 is less than 5&#8243;;</p>
<p>}</p>
<p>The above code does several things. First, I define $1 as &#8220;1&#8243;. I then use the syntax</p>
<p>if(VALUES) {</p>
<p>CODE TO EXECUTE;</p>
<p>}</p>
<p>Note that I enclose the IF values in between parentheses. In this specific instance, I will not use a semicolon after the brackets. This is one of the only times a semicolon will not be used. The compiler checks and sees that 1 not greater than 5. Since the IF statement returns FALSE, the compiler will execute the code in ELSE.<br />
Note: An else statement is not required. If you only have an IF statement and that statement returns false, the compiler will continue on with other parts of the code.</p>
<p>Since the IF statement is FALSE, the user would view:</p>
<p>1 is less than 5</p>
<p>Note that there are many options with IF statements. Follow the below syntax for all of your IF statements.</p>
<p>Variable versus another variable or number.</p>
<p>if($variable &gt; $/#) &#8211; Checks to see if a variable is greater than a variable/number.<br />
if($variable &lt; $/#) &#8211; Checks to see if a variable is less than a variable/number.<br />
if($variable &gt;= $/#) &#8211; Checks to see if the var is greater/equal to a var/number.<br />
if($variable &lt;= $/#) &#8211; Checks to see if the var is less than/equal to a var/number.<br />
if($variable == $/#) &#8211; Checks to see if the var is equal to a variable/number.</p>
<p>Variable versus string</p>
<p>Use the same syntax as above, however you need to use quote marks around the string.</p>
<p>Example:</p>
<p>if($variable == &#8220;String&#8221;), if($variable &lt; &#8220;String&#8221;)</p>
<p>IF statements can also include two parameters. To link two parameters we have two options.</p>
<p>If you want to have two possibilities (if x = x OR x = y)&#8230;</p>
<p>if(($variable1 == $variable2) || ($variable1 &lt; $variable3))</p>
<p>The above checks to see if $variable1 is equal to v2. If that isn&#8217;t the case, it will also check to see if $variable1 is less than v3. You can do this with AND.</p>
<p>If you want to combine two IF statements into one&#8230;</p>
<p>if(($variable1 == $variable2) &amp;&amp; ($variable1 &lt; $variable3))</p>
<p>Now you can make IF statements as complex as you want. Make sure you you use proper syntax. With the below statement I will have two cases.</p>
<p>if((($variable 1 == $variable2) &amp;&amp; ($variable3 &lt; $variable4)) || ($cat == $dog))</p>
<p>The above statement is fairly complex. First it checks to see if var1 is equal to var2. If that statement is true, it checks to see if var3 is less that var4. If both of those statements are true, it will return the entire IF statement as TRUE. Now, if var1 is not equal to var2 or var3 is not less than var 4 it will continue with<br />
the statement. If the the first part is FALSE it will check to see if cat is equal to dog. If that portion of the statement is true, it will return the entire IF statement as true. Note, var1 could be equal to var2 OR var3 could be less than var4. Unless the first two parts are equal, that portion of the IF statement will be<br />
FALSE. This can be hard to understand, so review the statement several times until you fully understand it. I now want to add on one more option. In addition to the == (equal to) you can also use != (not equal to). != can be used wherever == can be used and visa versa.</p>
<p>Now that we have IF statements down, I will tell you that you can use more than one IF statement inside another. This basically does the same thing as above, but in this case you are expanding it out. I will show you the above IF statement divided into two parts.</p>
<p>if($variable1 == $variable2) {</p>
<p>if($variable3 &lt; $variable4) {</p>
<p>}</p>
<p>}</p>
<p>else if($cat == $dog) {</p>
<p>}</p>
<p>The above does several things. First, it checks to see if var1 is equal to var2. If that&#8217;s true, it checks to see if var3 is less than var4. As mentioned above, both portions need to be true in order for that part of the statement is true. It doesn&#8217;t matter if var3 is less than var4 if var1 is not equal to var2. In this case we did<br />
not want to use just ELSE. If we used ELSE no matter the outcome of the first part, we would surely execute our statement. I used ELSE IF to connect the two together. I could have technically made $cat == $dog it&#8217;s own IF statement.</p>
<p>if($variable1 == $variable2) {</p>
<p>if($variable3 &lt; $variable4) {</p>
<p>}</p>
<p>}</p>
<p>if($cat == $dog) {</p>
<p>}</p>
<p>The above does the exact thing as the two previous examples. One time when ELSE IF comes in handy is when you are checking to see if one particular variable equals something.</p>
<p>if($home == &#8220;1&#8243;) {</p>
<p>}</p>
<p>else if($home == &#8220;2&#8243;) {</p>
<p>}</p>
<p>else if($home == &#8220;3&#8243;) {</p>
<p>}</p>
<p>else {</p>
<p>}</p>
<p>The above allows us to divide up home and assign different outcomes based on the value of home. I will now go back and show you how we can execute our menu.</p>
<p>Home<br />
Links<br />
Your Profile<br />
Post News<br />
Register an Account</p>
<p>I will use the variable $account. Here are the options.</p>
<p>If the user does not have an account, $account will equal nothing (&#8221;"). If the user is logged in under a normal account, $account will be equal to &#8220;normal&#8221;. If the user is an administrator, $account will be equal to &#8220;admin&#8221;. Since account will not be equal to multiple things, I will use separate IF statements. Note that the below code would be incorrect in an actual php page. The option names would have to be replaced with actual code.</p>
<p>Home<br />
Links<br />
if(($account == &#8220;normal&#8221;) || ($account == &#8220;admin&#8221;)) {<br />
Your Profile<br />
}<br />
if($account == &#8220;admin&#8221;) {<br />
Post News<br />
}<br />
if($account == &#8220;&#8221;) {<br />
Register an account<br />
}</p>
<p>The reason I don&#8217;t use ELSE IF in this case is becase multiple things could be shown at once. ELSE IF would be used if there is only one outcome. With the above example, Home and Links are displayed no matter what. If the user is a regular member or an administrator, they will be able to view their profile. If the user is an administrator, they will be above to post news. If the user is not a member at all ($account == &#8220;&#8221;, or nothing), they will have the option to register a new account. It is very common to receive a parse error when working with IF statements. Make sure you use correct syntax, you close all of your brackets, and you don&#8217;t add semicolons after the brackets. There are many other cases when the IF statement could be used. You will see this material in later tutorials.</p>
<p><strong>THIS tutorial was written by Christopher Airey. Chris works as the lead system administrator at ReadySetConnect Web Hosting. Looking for <a href="http://www.readysetconnect.com">a good PHP web host</a> for your scripts?<br />
</strong></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/05/php-tutorial-if-statements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial #2 &#8211; POST/GET Functions</title>
		<link>http://blog.readysetconnect.com/2008/05/php-tutorial-2-postget-functions/</link>
		<comments>http://blog.readysetconnect.com/2008/05/php-tutorial-2-postget-functions/#comments</comments>
		<pubDate>Wed, 14 May 2008 02:03:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php tutorials]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=13</guid>
		<description><![CDATA[In Tutorial 1 I discussed the basics of PHP. I went over the things you can do with PHP, advantages of using PHP, basic syntax, use of variables, and a few things to look out for when coding. In this tutorial, I will go over the basic POST/GET functions and the different ways they can [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>In Tutorial 1 I discussed the basics of PHP. I went over the things you can do with PHP, advantages of using PHP, basic syntax, use of variables, and a few things to look out for when coding. In this tutorial, I will go over the basic POST/GET functions and the different ways they can be used.</p>
<p>POST/GET are two functions used in forms. Before I continue, let me explain the pros and cons of both.</p>
<p>The POST function:</p>
<p>The POST function is a great tool when you work with PHP-based websites. There are many advantages to using it. I use the POST function as much as I can for I feel that it is more secure. For example, when you want the users to submit data to the server, you don&#8217;t want them to be able to change the information once it&#8217;s posted. In some cases that may be good, but if you have hidden fields that you do not want changed, using anything besides the POST method could be bad. Let&#8217;s say you have a form where the username must be more than 3 characters but less that 10. By using the POST method, you can secure the page so you are sure the data is within those limits. However, the only downside to using the POST method is that the data must stay on the same server. You can not have a form on one server and POST to another.</p>
<p>The GET function:</p>
<p>There are two cases where you would use the GET function. The first would be when you are submitting data from a form. This method is not always the best because the user can change the data once it is submitted. If your results page isn&#8217;t coded correctly, you could face major security risks. As far as submitting data goes, it is best to avoid the GET function. The only time it can be useful is when you are sending data between servers. However, you need to make sure the destination script will check for any changes or flaws in the data the user submitted.</p>
<p>The GET function can be used in a good way. Unlike the POST method, you do not need a form to use GET. The GET function can retrieve information from the url that can be crucial to a website. For example, some sites have one main page (mainly index.php) that calls any other pages. My site, www.ChrisAirey.com, does this. If you click a link on my site, you will be sent to index.php?id= where id equals the destination page. Based on the value of id, the script will call up the necessary files. Sometimes websites have certain options that will change based on the url. I will explain these methods later in this tutorial.</p>
<p>Now let&#8217;s examine the POST method.</p>
<p>As I have said before, I recommend naming all of your pages with a .php extension. However, it is not required for your php form. Unless you have other PHP content on the page, the form is 100% HTML. Below is a sample form that will submit username and password.</p>
<p>## Ex 2.1 ##</p>
<p>&lt;form action=&#8221;post.php&#8221; method=&#8221;POST&#8221;&gt;<br />
&lt;input type=&#8221;text&#8221; name=&#8221;username&#8221;&gt;&lt;br&gt;<br />
&lt;input type=&#8221;password&#8221; name=&#8221;password&#8221;&gt;&lt;br&gt;<br />
&lt;input type=&#8221;submit&#8221; value=&#8221;Log In&#8221;&gt;&lt;br&gt;<br />
&lt;/form&gt;</p>
<p>## Ex 2.1 ##</p>
<p>The above form will send the username and password to post.php. Note that you must specify what method you are using. If you do not specify a method, the form will use the GET method.</p>
<p>Now let&#8217;s look at post.php. The main job of this page is to retrieve the information that was posted to it. Sometimes it may insert the data into a database, other times it may query the database. The page may be simple and just echo out the information submitted. Or, it may email someone with a message from the original page. There are no set rules on what you can do with the POSTed information. In this case, we are<br />
going to echo out what was posted.</p>
<p>For our convenience, the information has already been put into a variable. However, it may be a good idea to change its name. Either way, our job is almost done.</p>
<p>The variable used for all data posted is $HTTP_POST_VARS. You can also shorten this by using $_POST. If you echo either $HTTP_POST_VARS are $_POST, the script will echo &#8220;Array&#8221;. The reason for this is that the $_POST variable contains multiple pieces of information. I will explain this with greater detail in the Array tutorial. In order to retrieve the username or password, you need to add the posted name in between<br />
brackets. If I wanted to retrieve the posted username, I would use $_POST[username]. Note, the name you put between the brackets is what you named it in the form. If you forget to name the input fields on the form, you will not be able to get that information through the destination script.</p>
<p>Below we will echo both the username and password.</p>
<p>## Ex 2.2 ##</p>
<p>&lt;?php</p>
<p>echo &#8220;The username you submitted was: $_POST[username]&lt;br&gt;&#8221;;<br />
echo &#8220;The password you submitted was: $_POST[password]&#8220;;</p>
<p>?&gt;</p>
<p>## Ex 2.2 ##</p>
<p>If I entered in &#8220;Chris&#8221; for the username and &#8220;Airey&#8221; for the password, the page would read:</p>
<p>The username you submitted was: Chris<br />
The password you submitted was: Airey</p>
<p>If you want to shorten the variable name, you will have to change it. However, you cannot change the name of the variable completely. Before we learned how to create a variable and add a value to it. We will do the same for this:</p>
<p>$username = $_POST[username];<br />
$password = $_POST[password];</p>
<p>Now we will redo the above script with the new variables.</p>
<p>## Ex 2.3 ##</p>
<p>&lt;?php</p>
<p>$username = $_POST[username];<br />
$password = $_POST[password];</p>
<p>echo &#8220;The username you submitted was: $username&lt;br&gt;&#8221;;<br />
echo &#8220;The password you submitted was: $password&#8221;;</p>
<p>?&gt;</p>
<p>## Ex 2.3 ##</p>
<p>When you view the page, the information will be the same as it was above. One thing to remember, if you echo $_POST[username] again, you will get the original value. This can be good for several reasons. I generally use this when encrypting a password. The below script shows how you can change a variable&#8217;s information yet still view what was originally posted.</p>
<p>## Ex 2.4 ##</p>
<p>&lt;?php</p>
<p>$username = $_POST[username];</p>
<p>$username = &#8220;($username)&#8221;;<br />
$password = &#8220;($_POST[password])&#8221;;</p>
<p>echo &#8220;The username you submitted was: $_POST[username]&lt;br&gt;&#8221;;<br />
echo &#8220;The password you submitted was: $_POST[password]&lt;br&gt;&#8221;;<br />
echo &#8220;The altered username you submitted was $username&lt;br&gt;&#8221;;<br />
echo &#8220;The altered password you submitted was $password&#8221;;</p>
<p>?&gt;</p>
<p>## Ex 2.4 ##</p>
<p>I added several things to the above script to show you how you can combine multiple methods. Before I continue, let me show you what the above script would have generated.</p>
<p>The username you submitted was: Chris<br />
The password you submitted was: Airey<br />
The altered username you submitted was (Chris)<br />
The altered password you submitted was (Airey)</p>
<p>First, I decided to create a variable username and fill it with the information supplied in $_POST[username]. After I made the variable, I decided to change it again. However, this time I added parentheses around the username. The process itself took me two steps. For the password, I cut out the first step. Instead of<br />
creating the variable then adding the parentheses in step two, I created the variable and added the parentheses at the same time. If I wanted to, I could have done everything as I echoed it. Example:</p>
<p>echo &#8220;The password you submitted was: $_POST[password]&lt;br&gt;&#8221;;<br />
echo &#8220;The altered password you submitted was ($_POST[password])&#8221;;</p>
<p>I will explain the uses of POSTed information with more depth as I get to database and management tutorials.</p>
<p>The GET method can be used for the same purposes as the POST method. I will cut this section fairly short since you retrieve the variable the same way. If you were making a form and wanted to retrieve the data, you could use either $HTTP_GET_VARS or $_GET. Everything else is the same as POST. The one difference between POST and GET is that you do not need to officially submit GET.</p>
<p>If you are not submitting data, you can change GET values just by altering the url.</p>
<p>When adding information to a url, you need to remember some basic syntax.</p>
<p>www.chrisairey.com/index.php?</p>
<p>For any webpage that uses GET data, you need to add a question mark after the file name. If the page you are querying is the index page, the file name isn&#8217;t even required. For example:</p>
<p>www.chrisairey.com/?</p>
<p>Since index.php is the directory page, I do not need to call it specifically. However, if I were querying post.php, I would need to include the entire path.</p>
<p>www.chrisairey.com/post.php?</p>
<p>Now to add the variables.</p>
<p>Adding a variable is quite simple. Just use variable=value. Below, id will be equal to home.</p>
<p>www.chrisairey.com/index.php?id=home.</p>
<p>If index.php had a script that read:</p>
<p>echo $_GET[id];</p>
<p>the returned value would be &#8220;home&#8221;. If you want to add more than one variable to a page, simply add the &amp; sign after each value.</p>
<p>www.chrisairey.com/index.php?id=home&amp;door=closed</p>
<p>If you do not want to define a value you can do the following:</p>
<p>www.chrisairey.com/index.php?id=home&amp;door=&amp;window=shut</p>
<p>Or, you can simply not name it at all. Remember, though, to add the &amp; sign after each variable. The &amp; sign is not required after the last variable in a string.</p>
<p>I&#8217;m now going to make a simple page with a menu.</p>
<p>&lt;a href=&#8221;index.php?id=start&#8221;&gt;Start&lt;/a&gt;&lt;br&gt;<br />
&lt;a href=&#8221;index.php?id=stop&#8221;&gt;Stop&lt;/a&gt;</p>
<p>You can clearly see that it is quite simple to define the GET variables. I will use these two functions (POST and GET) later in my tutorial series.</p>
<p>Need a <a href="http://www.readysetconnect.com">web hosting provider for your PHP scripts?</a> Try ReadySetConnect.com</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/05/php-tutorial-2-postget-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial #1 &#8211; The Basics</title>
		<link>http://blog.readysetconnect.com/2008/05/php-tutorial-1-the-basics/</link>
		<comments>http://blog.readysetconnect.com/2008/05/php-tutorial-1-the-basics/#comments</comments>
		<pubDate>Thu, 01 May 2008 23:11:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php programming basics]]></category>
		<category><![CDATA[php tutorials]]></category>

		<guid isPermaLink="false">http://blog.readysetconnect.com/?p=7</guid>
		<description><![CDATA[PHP is a scripting language used for many websites and network-driven tools. The language itself is very similar to C++, yet there are several differences. Here’s a basic summary on how the scripts work:The php “compiler” reads PHP files (.php or .php3 extension) off of the server.


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="entry">PHP is a scripting language used for many websites and network-driven tools. The language itself is very similar to C++, yet there are several differences. Here’s a basic summary on how the scripts work:The php “compiler” reads PHP files (.php or .php3 extension) off of the server. Based on input, the compiler will exectue certain parts of the php script. After processing this information, it will output the data to the user through HTML. If you do not know HTML, I suggest you learn it before continuing further.</p>
<p>
<script type="text/javascript"><!--
google_ad_client = "pub-8982953681202651";
/* 468x15, created 7/17/08 */
google_ad_slot = "8814018138";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>
PHP scripting can be very complicated, but it can do very amazing things. One key feature that makes php so successful is its database support. For most of my websites I use MySQL (www.mysql.com). Database support allows for many possibilities. You can create things such as user/member systems, user-input forms, news systems, and forum systems. Most common forum systems such as phpBB and Invision Power Board are codedin php.</p>
<p>PHP has been very successful for many reasons. First, it’s free off of www.php.net. It’s also fairly easy to make simple php scripts. However, you can make your scripts as complicated as you want. Some dynamic pages are very advanced and the files required contain several megabytes of code. It’s all up to you.</p>
<p>Before we begin I want to make several comments. First, scripting can be a pain in the butt. You will get “parse errors” that make no sense. Just take your time and try to figure it out. If you are careful, you won’t have much of a problem. I recommend you do not copy code from websites unless you know what the code does. It is often hard combining someone else’s code with yours. Try to figure out how their code works then incorporate that into your own. Finally, there are many ways to execute the same command. I recommend sticking with the examples I use for they are often less complicated than other methods. Using the same methods on all of your work makes everything very neat, and that is key when trying to solve errors.</p>
<p>Let’s begin…</p>
<p>I recommend changing all website files on your server from .htm/.html to php. Files with the .php extension will execute normally. This may seem confusing to the newcomer so I’ll try to explain it. The PHP compiler will only read files with the .php extension. However, it will only read code enclosed between the opening/closing tags. The opening and closing tags are the following &lt;?php and ?&gt;. Here’s an example:</p>
<p>If you have a file called index.php but there is no PHP code included, the php compiler will skip the file. NOTE: Do not include the php tags when you are using html. An error will be returned.</p>
<p>#####index.php with no php code#####</p>
<p>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Welcome to my web site&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
Hello World!<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>##### end of file #####</p>
<p>Now the next file is index.php with php code included.</p>
<p>#####index.php with php code#####</p>
<p>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Welcome to my web site&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php</p>
<p>echo “Hello World!”;</p>
<p>?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>##### end of file#####</p>
<p>The PHP compiler will read only the code between the &lt;?php and ?&gt; tags. In this case, the compiler would execute the line that reads ‘ echo “Hello World!”; ‘</p>
<p>The following file is index.html with PHP included.</p>
<p>#####index.html with php code#####</p>
<p>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Welcome to my web site&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php</p>
<p>echo “Hello World!”;</p>
<p>?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>##### end of file#####</p>
<p>When viewing the above file, the user would see the code itself. Because the file does not have a .php extension, the compiler will not check index.html for code.</p>
<p>When coding in PHP, I prefer to use Notepad of Vim. More information on this will be avaiable in the tutorial section of my website.</p>
<p>For the time being, you can use my PHP compiler found in the tutorial section. Enter in any example code to see the results.</p>
<p>Any line of code in php must end with a semicolon. There are several instances where this is not the case, but we will get into that later.</p>
<p>Let’s start with a sample script that will perform 1 task. We will get the script to “echo” or display a message on the screen.</p>
<p>## EX 1.1 ##</p>
<p>&lt;?php</p>
<p>echo “hello”;</p>
<p>?&gt;</p>
<p>## EX 1.1 ##</p>
<p>Note the script starts and ends with the PHP tags. The compiler will check and see that we told it to execute the “echo” command. Any text that follows will be echoed. However, with this simple command, there are already several things to look out for. First, make sure the words you want to echo are enclosed within double quote marks. Secondly, make sure your line ends with the semicolon (;). This tells the compiler that the command is finished. Lastly, be careful of using quote marks within other quote marks. The following line of code would be incorrect:</p>
<p>echo “I said “hi, how are you?”&#8221;;</p>
<p>There are several ways around this. First, you could use a single quote.</p>
<p>echo “I said ‘hi, how are you?’”;</p>
<p>Or, if you want to use double quotes, you could do the following:</p>
<p>echo “I said, \”hi, how are you?\”&#8221;;</p>
<p>Adding a “\” in front of many things such as quote marks and the $ sign will echo that actual symbol. It tells the compiler that the following symbol should be displayed, not viewed as a command or part of the script.</p>
<p>Now that we have the basic echo command down, let’s explore variables. Variables are tools that allow content to change based on the situation. For example, if you were making a login script and you wanted the site to read “Hello, (name)”. You could do this by using variables. I will explain that in a later tutorial. For now we will go over variable basics.</p>
<p>In order for a variable to be used, it must be defined. Defining a variable is quite simple. The following line will add the phrase “Hello World!” to the variable.</p>
<p>$sentence = “Hello World!”;</p>
<p>You can use as many variables as you want and you can name them whatever you want. Be careful not to use the same variable name for two different purposes in the same script. Now that the variable is defined, we can use it for many purposes. In this case, I want to echo the variable.</p>
<p>echo $sentence;</p>
<p>You do not need quote marks to echo the variable itself. However, if you want to echo the variable as part of a sentence you do.</p>
<p>echo “The man said \”$sentence\”&#8221;;</p>
<p>In the above line I combined several things. First I used a variable. Secondly, I used the \” to echo a quote around the variable. If the above was executed, the user would see the following:</p>
<p>The man said “Hello World!”</p>
<p>You can use variables for many things. If you want to do addition, subtraction, multiplication, or division you could assign numbers to the variables. If you are assigning a number to a variable, you do not need quote marks.</p>
<p>$1 = 1;<br />
$2 = 2;</p>
<p>You could use quotes if you wanted. Now, let’s do some math.</p>
<p>$answer = $1 + $2;</p>
<p>echo $answer;</p>
<p>The above would spit out “3″;</p>
<p>You can do longer equations such as:</p>
<p>$answer = $1 * $2 / $2 &#8211; $1;</p>
<p>As with the above, you do not need quotes.</p>
<p>If you want to display the actual equation on the screen you would need to use quotes and \.</p>
<p>echo “$1 \+ $2 = $1 + 2″;</p>
<p>The above would echo:</p>
<p>1 + 2 = 3</p>
<p>When the compiler reads the code, it notices that it should echo the first + sign. However, since the second plus sign is not preceded by a \ it views that as a function. There are several ways to do the above. You could do:</p>
<p>$answer = $1 + $2;</p>
<p>echo “$1 \+ $2 = $answer”;</p>
<p>Or, you could do the following. Note, you cannot echo two variables in a statement without the use of quotes.</p>
<p>$phrase = “$1 \+ $2 = “;<br />
$answer = $1 + $2;</p>
<p>echo “$phrase$answer”;</p>
<p>Note, you can run two variables one behind the other without a space in between. Had the phrase quote ended with the = sign, I would have added the extra space when I echoed. Example:</p>
<p>$phrase = “$1 \+ $2 =”;<br />
$answer = $1 + $2;</p>
<p>echo “$phrase $answer”;<br />
<strong>Tutorial Written by Christopher Airey. Chris works for ReadySetConnect as the lead server administrator. Looking for a <a title="php web hosting provider" href="http://www.readysetconnect.com/">php web hosting provider</a>. Try ReadySetConnect Web hosting.</strong></p>
</div>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.readysetconnect.com/2008/05/php-tutorial-1-the-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

