DYWBH Posted June 20, 2011 Share Posted June 20, 2011 I am trying to make it so if the admin user logs in it directs them to the admin page. I am using sessions. <?php error_reporting (E_ALL ^ E_NOTICE); session_start(); $userid = $_SESSION['userid']; $username = $_SESSION['username']; ?> Here is the code i'm using: if ($username = 'admin'){ header("Location: ./admin.php"); } else However, it is directing to the admin.php page even if you aren't the admin or even if youre not logged in! What's wrong with my code? Also, is this the best way to go around having an admin page? What other ways would you suggest? Thanks Link to comment https://forums.phpfreaks.com/topic/239928-if-username-admin/ Share on other sites More sharing options...
AbraCadaver Posted June 20, 2011 Share Posted June 20, 2011 == Link to comment https://forums.phpfreaks.com/topic/239928-if-username-admin/#findComment-1232447 Share on other sites More sharing options...
fugix Posted June 20, 2011 Share Posted June 20, 2011 I will elaborate on what abra posted in case you don't understand what he is trying to say. You need to use the correct operator when comparing the $username variable to 'admin' if ($username == 'admin'){ header("Location: ./admin.php"); } else Link to comment https://forums.phpfreaks.com/topic/239928-if-username-admin/#findComment-1232453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.