Jump to content

If username = admin


DYWBH

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.