Jump to content

What's wrong with this if statement? Simple test won't work..


virtuexru

Recommended Posts

I'm trying to create a rule, if a user is logged in, he see's this menu button. If he's not, he doesn't see it. I see it regardless or not if the user is logged in....

<?
  if (isset($_SESSION['image_is_logged_in']))
    {
      echo "<a href='main.php'>My Profile</a>";
    }
  else
    {
      echo "<a href='register.php'>Register</a>";
    }
?>

Should I be doing if($_SESSION['image_is_logged_in'] = true) {} else {} ?
Link to comment
Share on other sites

When the user logs out what is the [b]$_SESSION['image_is_logged_in'][/b] variable set to.

ALso the following code does not check the value of the variable but the existance of it:
[code]if (isset($_SESSION['image_is_logged_in']))[/code]

You'll want to add an [b]and[/b] expression (&&) after the isset function to see if the variables value is true, like so:
[code=php:0]if (isset($_SESSION['image_is_logged_in']) && $_SESSION['image_is_logged_in'] == TRUE)[/code]
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.