PHP develops us...LOGIN

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.

1616.png

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'])){
// 如果已经登录过,直接退出
  if(isset($_SESSION['id'])) {
    //重定向到管理留言
    echo "<script language=javascript>alert('您已登陆');window.location='index.php'</script>";
    // 登录过的话,立即结束
    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);

// 检查帐号和密码是否正确,
  $sql="SELECT * FROM user where name='$nickname' and password='$password'";
  $re = mysqli_query($link,$sql);
  $result=mysqli_fetch_array($re);
// 如果用户登录正确
  if(!empty($result)) {
    //注册session变量,保存当前会话用户的昵称
    $_SESSION['id']=$result['id'];
    // 登录成功重定向到管理页面
    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.


Next Section
<?php //初始化session if(isset($_GET['tj']) == 'out'){ session_destroy(); echo "<script language=javascript>alert('退出成功!');window.location='landing.php'</script>"; } if(isset($_POST['submit'])){ // 如果已经登录过,直接退出 if(isset($_SESSION['id'])) { //重定向到管理留言 echo "<script language=javascript>alert('您已登陆');window.location='index.php'</script>"; // 登录过的话,立即结束 exit; } // 获得参数 $nickname=$_POST['username']; $password=$_POST['password']; //$password=md5($password); // 检查帐号和密码是否正确, $sql="select * from user where name='$nickname' and password='$password'"; $re = mysqli_query($link,$sql); $result=mysqli_fetch_array($re); // 如果用户登录正确 if(!empty($result)) { //注册session变量,保存当前会话用户的昵称 $_SESSION['id']=$result['id']; // 登录成功重定向到管理页面 echo "<script language=javascript>alert('登陆成功');window.location='index.php'</script>"; } else { // 管理员登录失败 echo "<script language=javascript>alert('密码不正确');window.location='landing.php'</script>"; } } ?>
submitReset Code
ChapterCourseware