[英]how do i prevent logged in users from accessing the login page?
i have been trying to prevent user that are logged in not to go back to the login page.我一直试图阻止未登录到 go 的用户返回登录页面。 please i need your help.拜托我需要你的帮忙。 i've tried different method, but yet to no avail.我尝试了不同的方法,但仍然无济于事。 i will be much grateful if anyone can help me.如果有人能帮助我,我将不胜感激。 Thanks.谢谢。
here is my php code for login这是我的 php 登录代码
<?php
require 'connection.php';
session_start();
$_SESSION['message'] = '';
if(isset($_POST['login']))
{
if(empty($_POST['student']) || empty($_POST['pass']))
{
$_SESSION['message'] = " student id and password is required";
}
else
{
$password = md5($_POST['pass']);
$student = $_POST['student'];
$query= "select studentid, password, status from student_register where studentid='$student' and password='$password'";
$result=mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
if($row)
{
$_SESSION['user']=$_POST['student'];
$_SESSION['stat'] = $row['status'];
$_SESSION['message'] =" Login successfully";
header("refresh:5;url= Welcome.php");
}
else
{
$_SESSION['message'] =" Student id or password is incorrect";
}
}
}
else
{
}
?>
You can add a small code into you login.php
file to check the user already login or not.您可以在login.php
文件中添加一个小代码来检查用户是否已经登录。
if (isset($_SESSION['user']))
{
header("LOCATION: Welcome.php");
}
If session is already set, redirect it back to welcome.php
.如果 session 已设置,请将其重定向回welcome.php
。
Use this code for those pages which require login to access the page.将此代码用于需要登录才能访问该页面的页面。
if (!isset($_SESSION['user']))
{
header("LOCATION: login.php");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.