0
<?php
if (!isset($_SESSION['loginAdmin']) || ($_SESSION['loginAdmin'] == '')) {
    header ("Location: loginam.php");
} else {
    include('head2.php');
}


  if (!isset($_SESSION['login']) || ($_SESSION['login'] == '')) {
    header ("Location: login.php");
} else {
    include('head3.php'); 
}

?>  

I'm really stuck at this problem. What I want to do is to be able to redirect the user to another page base on the information entered.

My problem is:

if this statement is true:

else {
        include('head3.php'); 
    }

This one would also be true:

if (!isset($_SESSION['loginAdmin']) || ($_SESSION['loginAdmin'] == '')) {
        header ("Location: loginam.php");
    } 

Leading me to the login page whether I'm admin or just ordinary user. Is it possible two separate the two if statements so that if this is true:

else {
    include('head3.php'); 
}

Then this statement shouldn't get in the way and redirect me back to the login page:

if (!isset($_SESSION['loginAdmin']) || ($_SESSION['loginAdmin'] == '')) {
    header ("Location: loginam.php");
} 
2
  • I assume you started the session right after the opening tag, right? Commented May 26, 2010 at 5:33
  • yup right after the opening is there anything wrong with that? Commented May 26, 2010 at 6:08

2 Answers 2

2

Always use exit after sending Location: header

Tip: (!isset($var || $var == '') could be shortened to empty($var)

Sign up to request clarification or add additional context in comments.

2 Comments

I get two headers when I do this.
@user225269 so, that's why I've told you to use exit. To prevent getting 2 headers. Anyway, no matter what you get, you ought tu use exit after location. And you'd better begin to understand that.
1

What you can do is.. have a variable called usertype...

$_SESSION['usertype'] = 1 //for admin
$_SESSION['usertype'] = 2 //for regular user

Now Depending on the type of user, you can redirect the user.

if($_SESSION['usertype'] == 1)
header ("Location: admin.php");
else if($_SESSION['usertype'] == 2)
header ("Location: user.php");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.