Php+mysql+session Login Instance program code _php tutorial

Source: Internet
Author: User
In PHP we want to log in generally we are combined with the MySQL session of the two combined implementation, below I give an example to introduce the Php+mysql+session login Instance program code, there is a need to learn friends can refer to.

Instance

The code is as follows Copy Code

Remove unsafe HTML code for PHP and MySQL.
function Safestrip ($string) {
$string = Strip_tags ($string);
$string = mysql_real_escape_string ($string);
return $string;
}

Login Information Display function
function messages () {
$message = ";
if ($_session[' success '! = ') {
$message = ''
. $_session[' success ']. '';
$_session[' success '] = ';
}
if ($_session[' ERROR ']! = ") {
$message = ''
. $_session[' ERROR ']. '';
$_session[' ERROR '] = ';
}
return $message;
}

User Login function
function login ($username, $password) {

Filter user-entered username and password
$user = Safestrip ($username);
$pass = Safestrip ($password);

Convert password to MD5 format
$pass = MD5 ($pass);

Query whether the user name and password match in the database
$sql =
mysql_query ("select * from user_table WHERE username = ' $user '
and password = ' $pass ') or Die (Mysql_error ());

If the =1 indicates a successful certification
if (mysql_num_rows ($sql) = = 1) {

Start recording in session
$_session[' authorized ') = true;

Reload page
$_session[' success ' = ' login successful ';
Header (' Location:./index.php ');
Exit

} else {
Login failures are logged in session
$_session[' ERROR ' = ' Sorry, the user name or password you entered is incorrect ';
}
}
?>

The principle is simple, the user submits the user name and password and then we go through the security processing, and then to MySQL to compare the exact comparison if the same log on successfully.

http://www.bkjia.com/PHPjc/628714.html www.bkjia.com true http://www.bkjia.com/PHPjc/628714.html techarticle in PHP we want to log in generally we are combined with the MySQL session of the two combined implementation, below I give an example to introduce the Php+mysql+session login Instance program code, there is need to learn ...

  • 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.