Php Tutorial User cookie login verification and mysql tutorial data login verification method
<? Php
Unset ($ username );
If ($ _ COOKIE ['login']) {
List ($ c_username, $ cookie_hash) = split (',', $ _ COOKIE ['login']);
If (md5 ($ c_username. $ secret_word) = $ cookie_hash ){
$ Username = $ c_username;
} Else {
Print "You have sent a bad cookie .";
}
}
If ($ username ){
Print "Welcome, $ username .";
} Else {
Print "Welcome, anonymous user .";
}
?>
Check out the complete logon code for connecting to the database tutorial.
<Html>
<Head>
<Title> Log-In Page </title>
</Head>
<Body>
Please enter your user details to log-in here...
<Form action = "authenticate. php" method = "post">
Username: <br>
<Input type = "text" name = "username">
<Br>
Password: <br>
<Input type = "text" name = "password">
<Br>
<Input type = "submit" value = "Log In">
</Form>
</Body>
</Html>
File: authenticate. php
<? Php
$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['password'];
$ Self = $ _ SERVER ['php _ SELF '];
$ Referer = $ _ SERVER ['http _ referer'];
If ((! $ Username) or (! $ Password ))
{Header ("Location: $ referer"); exit ();}
$ Conn = @ mysql_connect ("localhost", "userName", "password") or die ("cocould not connect ");
$ Rs = @ mysql_select_db ("my_database", $ conn) or die ("cocould not select database ");
$ SQL = "select * from users where user_name =" $ username "and password = password (" $ password ")";
$ Rs = mysql_query ($ SQL, $ conn) or die ("cocould not execute query ");
$ Num = mysql_numrows ($ rs );
If ($ num! = 0)
{
$ Msg = "}
Else
{
Header ("Location: $ referer"); exit ();
}
?>
<Html>
<Head>
<Title> Log-In Authenticated </title>
</Head>
<Body>
<? Php echo ($ msg);?>
</Body>
</Html>