Complete, simple, working example of a login screen-system using php functions cookies and a mysql database for begginers. // This first if statement checks to see if we have a username/pass submited by the form, if it does then it attempts to validate it. if($username && $password) { mysql_connect() or die ("Whoops"); // Connect to the database, or if connection fails print error message. $password = md5($password); // encode submited password with MD5 encryption and store it back in the same variable. If not on a windows box, I suggest you use crypt() $sql = "select * from login where username='$username'"; // query statment that gets the username/password from 'login' where the username is the same as the one you submited $r = mysql_db_query("register",$sql); // Execute Query // if no rows for that database come up, redirect. if(!mysql_num_rows($r)) header("Location: $SCRIPT_NAME"); // This is the redirection, notice it uses $SCRIPT_NAME which is a predefined variable with the name of the script in it. $user = mysql_fetch_array($r); // if we got passed the last if statment means we have a registered username, get the rest of the info and put it in an array named $user if($user["password"] == $password) { // If the password stored in the database is the same as the password the user entered (which is now encryped with MD5) $password = serialize($password); // if we get this far we know we have a registered username, and the password matches. // serialize() the already incrypted password just for fun and mabey some extra security for when we store it in a cookie setcookie("candle_login","$username $password"); // Set the cookie named 'candle_login' with the value of the username (in plain text) and the password (which has been encrypted and serialized.) // set variable $msg with an HTML statement that basically says redirect to the next page. The reason we didn't use header() is that using setcookie() and header() at the same time isn't 100% compatible with all browsers, this is more compatible. $msg = ""; }else{ header("Location: $SCRIPT_NAME"); //If the password didn't match, redirect to this page in which $username and $password are reset therefore the first if () never gets executed } } if($msg) echo $msg; //if $msg is set echo it, resulting in a redirect to the next page. ?> // This is the login screen