PHP login function code Example of PHP implementing a simple login function
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:55:58
Original
941 people have browsed it
-
- /**
- * php login function
- * edit: bbs.it-home.org
- */
- // 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'].'< ;/span>';
- $_SESSION['success'] = '';
- }
- if($_SESSION['error'] != '') {
- $message = ' .$_SESSION['error'].'';
- $_SESSION['error'] = '';
- }
- return $message;
- }
-
- // User login function
- function login($username, $password){
-
- //Filter the username and password entered by the user
- $user = safestrip($username);
- $pass = safestrip($password);
-
- //Convert the password to md5 format
- $pass = md5($pass);
-
- // Query whether the username and password in the database match
- $sql = mysql_query("SELECT * FROM user_table WHERE username = '$user'
- AND password = '$pass'") or die(mysql_error());
-
- //If = 1, the authentication is successful
- if (mysql_num_rows($sql) == 1) {
-
- //Start recording in the session
- $_SESSION['authorized'] = true;
-
- // Reload the page
- $_SESSION['success'] = 'Login successful';
- header('Location: ./index.php');
- exit;
- } else {
- // Login failure record In session
- $_SESSION['error'] = 'Sorry, the username or password you entered is incorrect';
- }
- }
- ?>
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31