Quote:
Originally Posted by xited1@cox.net
So I'm guilty of copying and pasting or writing code that I don't fully understand, I just know it's supposed to do something from all the books and tutorials and forum posts. I have this one snippet of code that I would like someone to explain to me what all the characters are for and what exactly the code is supposed to do. Can someone help me out here? (I do know the session start part of it...imagine that!)
Code:
<?
session_start();
if (@$_SESSION['auth'] != "yes")
{
header("Location: register.php");
exit();
}
?>
|
Hiya,
basically line-by-line:
1) start the session
2) check if session variable "auth" is set - the "at - @" is there to surpress any warning messages in case the session variable is not set yet
3) if the session variable does not exist redirect to the register page (if you want it to redirect elsewhere you could try: header('Location: ./inc/register.php') or header('Location: ' . $_SERVER['PHP_SELF'] . '?page=register')...
4) exit() is there to make sure none of the code below redirection to another page gets executed, personally I believe it is a blast from the past when PHP use to do that but you can't do any harm leaving it there - I do...
Good luck,
hoopyfrood