سؤال

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