Link to home
Start Free TrialLog in
Avatar of smetterd
smetterdFlag for United States of America

asked on

Can't get session variable to stick!

Can't get session variable to stick!

<?php
      if (!isset($_SESSION)) {
        session_start();
      }  

 
 if($_GET['detail'] == 0){
      (($_SESSION['detail'])==0);
} elseif($_GET['detail'] ==1){
      (($_SESSION['detail'])==1);
}else {
      echo "ERROR";
}
?>
sessionDetail is <?php echo $_SESSION['detail']; ?><br>
getDetail is <?php echo $_GET['detail']; ?><br>
httpReferrer is <?php echo $_SERVER['HTTP_REFERER']; ?>


-----
Returns:
----
sessionDetail is
getDetail is 1
httpReferrer is http://elearn.sbcisd.net/walkthrough/inc_palm_menu.php
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try add session_start() at the top of your page, like:

<?php

session_start();

      if (!isset($_SESSION)) {
        session_start();
      }  

...
ASKER CERTIFIED SOLUTION
Avatar of _Marcel_
_Marcel_
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of smetterd

ASKER

Also needed to remove the unnecessary quotes around SESSION... They were causing an error
The following code works perfectly. Thanks!


<?php
      if (!isset($_SESSION)) {
        session_start();
      }  

 if($_GET['detail'] == 0){
      ($_SESSION['detail']=0);
} elseif($_GET['detail'] ==1){
      ($_SESSION['detail']=1);
}else {
      echo "ERROR";
}
?>
sessionDetail is <?php echo $_SESSION['detail']; ?><br>
getDetail is <?php echo $_GET['detail']; ?><br>
httpReferrer is <?php echo $_SERVER['HTTP_REFERER']; ?>