Question

I have a if/elseif statement that I am passing a GET variable into. Once inside the corrent block, I can echo something to make sure that I am in the right place. Once there, I have tried several times to set a session variable but it isn't working properly. I'm sure that I'm not doing something right.

if(isset($_GET['mygetvar'])){
  $_SESSION['flag'] = 'on';
}else{
  $_SESSION['flag'] = 'off';
}

When I check the link to take me to the first block, I'm expecting to see the flag on but I get nothing at all. I have already started the session at the very top of the page. All I want to do is use this session as a flag. If its on, do something else don't. I basically want to use this as a switch.


EDIT: Here is the actual code. The avove was an example. If you guys should find a syntax error in this code, then there really is an error. I dont think so because I can echo what's inside the code blocks just fine.

if(isset($_GET['out']))
{
    $_SESSION['rim'] = 'on';
    echo 'out';
}
else
{
    $_SESSION['rim'] = 'off';
    echo 'in';
}

Ok, here is what is going on.... When I do print_r($_SESSION); inside the if/else blocks, I can see the correct results echo. Is this normal?

No correct solution

OTHER TIPS

Did you remember to call session_start() beforehand?

if($_GET(['mygetvar']))

is wrong ($_GET is not a function, but an array). Also, you probably want to be testing whether that query param exists or not, so try

if(isset($_GET['mygetvar']))

$_SESSION is an array. You should have

if($_GET['mygetvar']){

Note the square bracket around $mygetvar

EDIT: And you should probably do

if(isset($_GET['mygetvar'])){
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow