Forum Moderators: coopster

Message Too Old, No Replies

Session dropping variable

         

fraser1980

4:01 pm on Aug 12, 2008 (gmt 0)

10+ Year Member



I am having trouble with session variables (this is my first go at working with them so excuse me if my error is something fundamental)

I have a mail form in my nav which posts to the current page (mail form works fine). In the head of each page, I have an include which points to the following piece of code:

<?php session_start();
if (isset($_REQUEST['email']))
$_SESSION['requested'] = "yes";
?>

This should check to see if the mail form has been filled out and set 'requested' in the session to 'yes'. In my understanding, when you navigate to other pages, 'requested' should remain as 'yes'.

To test the variable has been assigned, further down the page, I am trying to echo the 'requested' variable using:

<?php echo $_SESSION['requested'] ?>

This works fine on the initial page after the mail form. However, when I navigate to another page, it seems to forget all about "$_SESSION['requested']" and trying to echo this produces nothing.

Thankyou in advance for taking the time to look and if you would like more information please don't hesitate to ask.

Cheers
Fraser

gcarn

8:46 pm on Aug 12, 2008 (gmt 0)

10+ Year Member



do your other pages have the session_start(); at the very beginging of the page? You will need it as the first thing in any page involving your session.

fraser1980

8:08 am on Aug 14, 2008 (gmt 0)

10+ Year Member



Hi,

They do yes. I have put the following header code in it's own file which is called with an include at the top of every page.

<?php session_start();
if (isset($_REQUEST['email']))
$_SESSION['requested'] = "yes";
?>

Thanks
Fraser

barns101

10:33 am on Aug 14, 2008 (gmt 0)

10+ Year Member



Is your browser accepting the session cookie?

StoutFiles

11:49 am on Aug 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try putting the session_start() before the include. Not sure, just throwing out ideas.

[edited by: StoutFiles at 11:49 am (utc) on Aug. 14, 2008]

gcarn

1:17 pm on Aug 14, 2008 (gmt 0)

10+ Year Member



I have had things like this happen, drive me crazy, to realize only that my devolper browser toolbar had cookies disabled checked for some random reason.

*shrugs*
Sessions generally work very simply, im not too sure whats going wrong for you

fraser1980

2:48 pm on Aug 14, 2008 (gmt 0)

10+ Year Member



Thanks for all the help guys.

Not sure what I did but it seems to be working OK now....

Still very confused but all seems good.

Cheers again
Fraser