PHP develops user login function of simple book lending system
We have successfully registered and saved the information in the database.
Now we can fill in the registered information in the login text box. As long as the login information matches the registration information, we can successfully log in and jump to the home page.
Here you need to judge the submit in <input>.
Determine whether you are logged in based on the id stored in the session. If you are already logged in, the login will end.
<?php if(isset($_POST['submit'])){ // 如果已經(jīng)登錄過(guò),直接退出 if(isset($_SESSION['id'])) { //重定向到管理留言 echo "<script language=javascript>alert('您已登陸');window.location='index.php'</script>"; // 登錄過(guò)的話,立即結(jié)束 exit; } } ?>
session variables are used to store information about the user session (session), or to change the settings of the user session (session).
Get the POST parameters and check whether the username and password match through SQL statements.
<?php $nickname=$_POST['username']; $password=$_POST['password']; //$password=md5($password); // 檢查帳號(hào)和密碼是否正確, $sql="SELECT * FROM user where name='$nickname' and password='$password'"; $re = mysqli_query($link,$sql); $result=mysqli_fetch_array($re); // 如果用戶登錄正確 if(!empty($result)) { //注冊(cè)session變量,保存當(dāng)前會(huì)話用戶的昵稱 $_SESSION['id']=$result['id']; // 登錄成功重定向到管理頁(yè)面 echo "<script language=javascript>alert('登陸成功');window.location='index.php'</script>"; } else { // 管理員登錄失敗 echo "<script language=javascript>alert('密碼不正確');window.location='landing.php'</script>"; } ?>
md5() function is used to encrypt files.