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