Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Can't get session variable to stick!

Posted on 2007-07-26
3
Medium Priority
?
328 Views
Last Modified: 2013-12-12
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
0
Comment
Question by:smetterd
3 Comments
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 19574109
try add session_start() at the top of your page, like:

<?php

session_start();

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

...
0
 
LVL 8

Accepted Solution

by:
_Marcel_ earned 2000 total points
ID: 19574205
Try to set your SESSION with a single is (=), not with the double one (==), then you are only comparing...

<?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']; ?>
0
 
LVL 2

Author Comment

by:smetterd
ID: 19574279
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']; ?>
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question