view raw
nukman nukman - 6 months ago 31
PHP Question

Prevent user to access login page if has logged in

I want to try create login page which it can be accessed by user if has not logged in, this is my code,

if ($_SESSION['MM_Username'] != '') {
header ("Location: home.php");};

It works!
But, it generates an error "Notice: Undefined index: MM_Username in C:\xampp\htdocs\msd\index.php".
What should I do now?


Check the session exists or not using isset

if (isset($_SESSION['MM_Username'])) {
header ("Location: home.php");