The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Sessions!

OMG, I hate sessions! I think ive learnt that globals OFF suits me better though. Can someone point me to a tutorial that uses globals OFF. A simple sessions tutorial that helps u code the basic session for a login script. I really need one but i cant seem to find one that helps me enough .

because i dont know how to impliment this into the rest of my login.php code, so say it does the database checks, and if its all sucessfull etc, then the session is started using the submitted username, using the above code.

This is my login.php code if it helps(the part that would concern you): I submitted it seperate to make it easier to read.

PHP Code:

mysql_select_db($db)or die("Could not select the database");
if($loguser=="guest" && $logpass=="guest"){
echo "Thank you. You have logged in as <b>Guest</b>. You will be re-directed to the website very soon.";
echo "<META http-equiv='refresh' content='5;URL=index2.php'>";
}
else {
$query="SELECT * FROM users WHERE username='$loguser' && password='$logpass'";
$result=mysql_query($query);
if(mysql_num_rows($result) < 1){
echo "One or more of the details you tried were invalid, please go back and try again.";
}
else {
echo "Congratulations you logged in successfully as <b>$loguser</b>. You will be re-directed to the website very soon.";
echo "<META http-equiv='refresh' content='5;URL=index2.php?username=".$_POST['loginuser']."'>";
}

This is my login.php code if it helps(the part that would concern you): I submitted it seperate to make it easier to read.
<snip>

PHP Code:

mysql_select_db($db)or die("Could not select the database");
if($loguser=="guest" && $logpass=="guest"){
echo "Thank you. You have logged in as <b>Guest</b>. You will be re-directed to the website very soon.";
echo "<META http-equiv='refresh' content='5;URL=index2.php'>";
}
else {
$query="SELECT * FROM users WHERE username='$loguser' && password='$logpass'";
$result=mysql_query($query);
if(mysql_num_rows($result) < 1){
echo "One or more of the details you tried were invalid, please go back and try again.";
}
else {
session_destroy();
session_start();
$_SESSION['username'] = $loguser;
session_end();
echo "Congratulations you logged in successfully as <b>$loguser</b>. You will be re-directed to the website very soon.";
echo "<META http-equiv='refresh' content='5;URL=index2.php?username=".$_POST['loginuser']."'>";
}