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 Quote 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 == Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/239928-if-username-admin/#findComment-1232453 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.