i wrote this code but it is not working. simply check if some user is already login (with in a browser), if yes then don't show the login page - redirect user to dashboard.

<?php
session_start();
if(isset($_SESSION['usr']))
{
header('location:dashboard.php');   
}


error_reporting(0);

?>
有帮助吗?

解决方案

<?php
session_start();
echo $_SESSION['usr']; //just to check
if(isset($_SESSION['usr']))
{
header('location:dashboard.php');   
}
else
{
header('location:login.php');   
}
?>

check correctly that $_SESSION['usr'] is right. Is it usr or username like that? The above code is correct. If it is still not working, it means that there was an error while setting that session ur. recheck the code, to after login form. Try echo $_SESSION['usr']. so that it will make things more clear

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top