if( $_SESSION['user_id'] <> 1)
{ 
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 5; url='.$ref);

echo $_SESSION['user_id']; // <-----    echoes '1'

echo "<h2>Some feature is currently unavailable.</h2>You will be redirected to $ref in 5 seconds"; die; 
}

I've written this a hundred different ways and it still redirects even though the user_id accessing the page is '1'.

Recommended Answers

All 4 Replies

if( $_SESSION['user_id'] <> 1)
{ 
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 5; url='.$ref);

echo $_SESSION['user_id']; // <-----    echoes '1'

echo "<h2>Some feature is currently unavailable.</h2>You will be redirected to $ref in 5 seconds"; die; 
}

I've written this a hundred different ways and it still redirects even though the user_id accessing the page is '1'.

You might try the following modification:

if($_SESSION['user_id']>1) { 
    $ref = $_SERVER['HTTP_REFERER'];
    header( 'refresh: 5; url='.$ref);
    echo $_SESSION['user_id']; // <-----    echoes '1'
    echo "<h2>Some feature is currently unavailable.</h2>You will be redirected to $ref in 5 seconds"; die; 
} else {
    echo "<h2>You are the primary user with userid of ", $_SESSION['user_id'], "!";
}

Just my 2¢.

It actually did work. I had it set up as NOT EQUAL because there are actually a few different Id's I use. For the life of me I still can't figure out why it wouldn't work. The entire site is dynamic and from the login right up to that page everything is displayed according to user_id and was working fine.

Anyhow, I'm done stressing over it. It's good enough for now to allow me to play around in there and do what I need to.

Let's mark this one solved so I can actually get something done today.

Thanks Wraithmanilian.

My pleasure.

I think that the reason that it was not working is based in the logic. To be completely honest, I'm not sure why it wasn't working, either. I will defer to the greater knowledge that some of the others have. :)

Normally, the way I code a line like your if statement would be:

if( $_SESSION['user_id']!=1)

That's just my style, and I am sure that there are a hundred different ways of doing it, many of them better ways than mine. For later consideration, though, you might want to think about adding a column into your users database, an ENUM, set to 'A' for admin and 'U' for regular user. That way, you wouldn't have to try and hard-code the userid's into the code, and you wouldn't have to keep track of all the possible admin user_id numbers. So long as the column returns 'A' for usertype, then you can consider that person an admin, maybe even save the status in a session variable. :)

Just my 2¢.

I've tried <> 1, <> '1', != 1, != '1' . Weird.

User ids are set to session variable upon login so it was never an issue up until now.

Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.