nukman nukman - 1 year ago 59
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?

Answer Source

Check the session exists or not using isset

if (isset($_SESSION['MM_Username'])) {
header ("Location: home.php");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download