<?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>JB Blog</title>
	<atom:link href="http://jason-brook.co.uk/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://jason-brook.co.uk/blog</link>
	<description>Everything about web design</description>
	<lastBuildDate>Mon, 10 May 2010 21:35:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Checking if your users are logged in with PHP Login script</title>
		<link>http://jason-brook.co.uk/blog/?p=47</link>
		<comments>http://jason-brook.co.uk/blog/?p=47#comments</comments>
		<pubDate>Sun, 14 Mar 2010 11:38:14 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://jason-brook.co.uk/blog/?p=47</guid>
		<description><![CDATA[A little while back i wrote a tutorial on how to write a simple PHP Login script powered by a small MySQL database. After receiving many emails on the matter i have decided to write a tutorial on how you can check if a user is logged in and a page that will log them [...]]]></description>
			<content:encoded><![CDATA[<p>A little while back i wrote a tutorial on how to write a simple PHP Login script powered by a small MySQL database. After receiving many emails on the matter i have decided to write a tutorial on how you can check if a user is logged in and a page that will log them out and take them back to the login page.</p>
<h4>Things you need</h4>
<p>PHP 4 or 5 enabled server<br />
MYSQL database<br />
Some basic HTML and CSS Knowledge <em>(PHP knowledge isnt required i will tell you how to do it here)<br />
About 5 &#8211; 10 minutes</em></p>
<h4>Step 1 &#8211; Things to know</h4>
<p>Ok so the first important thing to know is that the original script is in need of a bit of editing which will be shown in step 2, we need to create a session on the users browser that our script will be looking for to check a user is logged in. The next thing to know is that in order to logout a user you will need to remove this session, otherwise a user could just keep going back to the secure page without logging in.</p>
<h4>Step 2 &#8211; Editing the old script</h4>
<p>Right then so in the old script we need find the following line.</p>
<p><code>if(mysql_num_rows($result)=="1")</code></p>
<p>Under that line where you will have something like</p>
<p><code>{<br />
header("Location: securepage.php");<br />
}</code></p>
<p>You will need to edit it to have this new line after the first { symbol and before we redirect the user. This is important if you place this line below the redirect the script will leave before you create the session.</p>
<p><code>session_register("logged1241");</code></p>
<p>The name you put between the brackets is very important and you should remember it for later on.</p>
<h4>Step 3 &#8211; Check if a user is logged in</h4>
<p>This is a simple yet effective script that will check the user is logged in. Just place this before the  tag on any of the secure pages. Note that the name of the session must be identical to that in step 2, if its not then no one will ever be able to access the page.</p>
<p><code>&lt;?<br />
session_start();<br />
if(!session_is_registered(logged1241)){<br />
header("location:login.php");<br />
}<br />
?&gt;</code></p>
<p>The above code basically searched for the session we made when the user logged in and if its not found then it will redirect the user to the login.php page, where they can login. By this being placed above the  tags it means that the user will not even get a glimpse of the secure page before they are forced to leave.</p>
<h4>Step 4 &#8211; Logout script</h4>
<p>This part is so simple to do, just create a new page called logout.php and inside the page put nothing but the following code snippet.</p>
<p><code>&lt;?<br />
session_start();<br />
session_destroy();<br />
{header("Refresh: 3; url='login.php'");}<br />
session_start();<br />
?&gt;</code></p>
<p>The user will be logged out and will be redirected back to the login.php page, to login again if they want.</p>
<p>Hope you enjoyed the tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason-brook.co.uk/blog/?feed=rss2&amp;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a simple PHP login page</title>
		<link>http://jason-brook.co.uk/blog/?p=15</link>
		<comments>http://jason-brook.co.uk/blog/?p=15#comments</comments>
		<pubDate>Sat, 27 Feb 2010 11:08:43 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[make]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jason-brook.co.uk/blog/?p=15</guid>
		<description><![CDATA[So people are always searching around for how to make a passworded area, it may look like a really daunting task to begin with, but it really isn&#8217;t that hard. In this tutorial i will explain how to setup and create a multi-user login page for your site.
Things you need
PHP 4 or 5 enabled server
MYSQL database
Some basic [...]]]></description>
			<content:encoded><![CDATA[<p>So people are always searching around for how to make a passworded area, it may look like a really daunting task to begin with, but it really isn&#8217;t that hard. In this tutorial i will explain how to setup and create a multi-user login page for your site.</p>
<h4>Things you need</h4>
<p>PHP 4 or 5 enabled server<br />
MYSQL database<br />
Some basic HTML and CSS Knowledge <em>(PHP knowledge isnt required i will tell you how to do it here)<br />
<span style="font-style: normal;">About 20 minutes </span></em></p>
<p>    <em><em><span style="font-style: normal;"><br />
<h4>Step 1 &#8211; Things to know</h4>
<p><span style="font-weight: normal;">This script is made for a small personal site and it is only the very basic that you can do for a MYSQL login system, if you wanted to have a more secure system then the use of encryption would be required. This script will stop about 90% of web users from accessing your site, but those more advanced in hacking sites and databases may still get through.</span></span></em></p>
<p>    <em><em><span style="font-style: normal;"><br />
<h4>Step 2 &#8211; Creating the login portal page</h4>
<p><span style="font-weight: normal;"> This is where your HTML and CSS knowledge comes into play, this part is super easy and in the example below i called the page &#8220;login.html&#8221; and it should contain a simple login form that will run the file we will make in step 3 called &#8220;login-run.php&#8221; the method to send the data should be POST.</span></span></em></p>
<p><code> &lt;form action="login-run.php" method="POST"&gt;<br />
&lt;input name="username" type="text" /&gt;<br />
&lt;input name="password" type="password" /&gt;<br />
&lt;input type="submit" value="Login Now" /&gt;<br />
&lt;/form&gt;</code></p>
<p><span style="font-style: normal;">I wont go on to explain this block of code as it is basic HTML and hopefully you know what is does and how it does it.</span></p>
<p>    <em><em><span style="font-style: normal;"><br />
<h4>Step 3 &#8211; Creating the database</h4>
<p><span style="font-weight: normal;"> Ok so make a new MYSQL database now, create a table called &#8220;users&#8221; and create 3 columns with the following names and values.<br />
id                          INT(4)                            AUTOINCREMENT<br />
username         VARCHAR(24)<br />
password          VARCHAR(24)</span></span></em></p>
<p><em></em></p>
<p><span style="font-style: normal;">So basically you are creating 3 columns, one is called &#8220;id&#8221; that is type INT and is 4 characters long this is the user id that is automatically made so it should have AUTO INCREMENT on so the database will automatically generate it. The next column is called &#8220;username&#8221; and it should be type VARCHAR as it contains non-numerical characters and the length should be around 24. The last column should be called &#8220;password&#8221; and have the same type and length as the username column.</span></p>
<p><span style="font-style: normal;">Once you have done this add one user to test with in my examples i used admin and password, for username and password.</span></p>
<p>    <em><em><span style="font-style: normal;"><br />
<h4>Step 4 &#8211; Creating the login-run script</h4>
<p><span style="font-weight: normal;"> This is where it gets hard if you have never written PHP before, we are now going to make the login script that actually checks your database for the users details. </span></span></em></p>
<p><em><span style="font-style: normal;">So our first task is to actually connect to the database so for this we need the following block of code</span></em></p>
<p><code>&lt;?<br />
$con = mysql_connect("localhost","dbuser","dbpass");<br />
if (!$con)<br />
  {<br />
  die('Could not connect: ' . mysql_error());<br />
  }<br />
?&gt;</code></p>
<p><em><span style="font-style: normal;"><strong><span style="font-weight: normal;">This code may be short but what it does is mighty, it will connect to the database with the name &#8220;dbuser&#8221; and password &#8220;dbpass&#8221; and will then check to see if it logged in ok if it didn&#8217;t get that far it will echo back and error to you on the page. Note that you will have to change dbuser and dbpass to your databases name and password.</span></strong></span></em></p>
<p><em><span style="font-style: normal;"><strong><span style="font-weight: normal;">Now for the next bit we want to get the information that the user just entered in our form for this we need to add this code under the block we just made. (Note the last thing on the page MUST be the <code>?&gt;</code> symbol, this ends the PHP code.</span></strong></span></em></p>
<p><code>$user = $_POST['username'];<br />
$pass = $_POST['password'];</code></p>
<p><em><span style="font-style: normal;">Ok so that bit of code will get your users information from the form and save it to two variables called &#8220;user&#8221; for the username and &#8220;pass&#8221; for the password.</span></em></p>
<p><em><span style="font-style: normal;">All that is left to do now is to search the database for that information and check if the user is allowed to enter, and then redirect them to the secure page. To do this add the following code block to the end of the document (remember the php end tag must be at the base of the document).</span></em></p>
<p><code>mysql_select_db("dbname", $con);</p>
<p>$result = mysql_query("SELECT * FROM users WHERE username='$user' AND password='$pass'");</p>
<p>if(mysql_num_rows($result)=="1")<br />
  {<br />
  header("Location: securepage.php");<br />
  }<br />
else {<br />
header("Location: login.html");<br />
}</p>
<p>mysql_close($con);</code></p>
<p><em><span style="font-style: normal;">The last thing you need to do is make a page called &#8220;securepage.php&#8221; this si where the user will go when they have logged in correctly. There you have it test it out and enjoy, there is so much more that you can do like checking if a user is logged in when they go to a page and to assign certain users different areas to access. If there is a need for this i will write another tutorial to show how to do that.</span></em></p>
]]></content:encoded>
			<wfw:commentRss>http://jason-brook.co.uk/blog/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 of my favourite blogs from around the web</title>
		<link>http://jason-brook.co.uk/blog/?p=12</link>
		<comments>http://jason-brook.co.uk/blog/?p=12#comments</comments>
		<pubDate>Fri, 26 Feb 2010 11:20:22 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Inspiration]]></category>

		<guid isPermaLink="false">http://jason-brook.co.uk/blog/?p=12</guid>
		<description><![CDATA[Here you can see a few of my top blogs from around the web enjoy.
Outlaw Design Blog
Lovely clean design, well made and has some simply amazing content for all.
http://www.outlawdesignblog.com/
Matt Mullenweg Blog
Who can argue Matt&#8217;s a highly influential person on the web, one that has an amazing blog to go with it.
http://ma.tt/ 
Web designer Wall
Nice layout and always very informative this is a [...]]]></description>
			<content:encoded><![CDATA[<p>Here you can see a few of my top blogs from around the web enjoy.</p>
<p><strong>Outlaw Design Blog</strong><br />
Lovely clean design, well made and has some simply amazing content for all.<br />
<a href="http://www.outlawdesignblog.com/"><em>http://www.outlawdesignblog.com/</em></a></p>
<p><strong>Matt Mullenweg Blog</strong><br />
Who can argue Matt&#8217;s a highly influential person on the web, one that has an amazing blog to go with it.<br />
<a href="http://ma.tt/"><em>http://ma.tt/</em></a><em> </em></p>
<p><em><span style="font-style: normal;"><strong>Web designer Wall</strong></span><br />
<span style="font-style: normal;">Nice layout and always very informative this is a great blog.</span><br />
<a href="http://www.webdesignerwall.com/">http://www.webdesignerwall.com/</a></em></p>
<p><em><strong><span style="font-style: normal;">Design Bit Blog</span></strong><br />
<span style="font-style: normal;">Well this blog stunned me with its great content, blogs this packed with web tips are rare, a great place for any web enthusiast. </span><br />
<span style="font-style: normal;"><em><a href="http://designbit.co.uk/">http://designbit.co.uk/<br />
</a></em></span></em></p>
<p><em><strong><span style="font-style: normal;">Web Designer Mag</span></strong><br />
<span style="font-style: normal;">Maybe not the most beautiful of blogs, but full to the brim with content for sure. </span><br />
<span style="font-style: normal;"><em><a href="http://www.webdesignermag.co.uk/">http://www.webdesignermag.co.uk/</a></em></span></em></p>
]]></content:encoded>
			<wfw:commentRss>http://jason-brook.co.uk/blog/?feed=rss2&amp;p=12</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>New Blog</title>
		<link>http://jason-brook.co.uk/blog/?p=10</link>
		<comments>http://jason-brook.co.uk/blog/?p=10#comments</comments>
		<pubDate>Thu, 18 Feb 2010 11:10:22 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[blog started]]></category>
		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://jason-brook.co.uk/blog/?p=10</guid>
		<description><![CDATA[Well i finally got around to it, i always wanted to setup a blog ever since i started my site up in late 2007, since the site has started getting more popular and the visit counts have risen. I thought to myself &#8220;Blog now&#8221; so here it is.
The blog has the same layout and theme [...]]]></description>
			<content:encoded><![CDATA[<p>Well i finally got around to it, i always wanted to setup a blog ever since i started my site up in late 2007, since the site has started getting more popular and the visit counts have risen. I thought to myself &#8220;Blog now&#8221; so here it is.</p>
<p>The blog has the same layout and theme as the main site, minus the jquery menu bar. I&#8217;m a big one for sharing ideas and helping others so the main focus of this particular blog will be, yes you guessed it, helping you with your web design and programming. I will be writing tutorials, leaking some big tips and showing loads of great sites from around the web so check back often for that and more.</p>
<p>Enjoy <img src='http://jason-brook.co.uk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jason-brook.co.uk/blog/?feed=rss2&amp;p=10</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
