Php user cookie login verification and mysql data login verification method

Source: Internet
Author: User
Tags mysql tutorial php tutorial

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.