Page 1 of 1

session variable cannot exist betwen pages.

Posted: Tue Mar 09, 2004 2:18 am
by victor
need some advice on my session variable, it is found as registered using the isset function however, when i try to call it out on another page it is gone, the following are the codes used to test the session viariable. Cookies have been enabled by the way.

1st page

<?php
session_start();

$HTTP_SESSION_VARS['sess_var'] = "Hello world!";

echo 'The content of $HTTP_SESSION_VARS[''sess_var''] is '
.$HTTP_SESSION_VARS['sess_var'].'<br />';
?>
<a href="page2.php">Next page</a>


2nd page

<?php
session_start();

echo 'The content of $HTTP_SESSION_VARS[''sess_var''] is '
.$HTTP_SESSION_VARS['sess_var'].'<br />';

unset($HTTP_SESSION_VARS['sess_var']);
?>
<a href="page3.php">Next page</a>

your help is appreciated.

Posted: Tue Mar 09, 2004 2:26 am
by markl999
Try a simple test first, like

Code: Select all

<?php
session_start();
if(empty($_SESSION['count'])){
  $_SESSION['count'] = 1;
} else {
  ++$_SESSION['count'];
}
echo 'Count is : '.$_SESSION['count'];
?>
This should increment the counter everytime you reload the page. Note how i used $_SESSION, not $HTTP_SESSION_VARS ( i presume you are using PHP => 4.1.0 :o )
If this works then the problems in your code, if it doesn't then you have general session problems.

session variable cannot exist betwen pages.

Posted: Tue Mar 09, 2004 2:41 am
by victor
yeah, the count is always 1 .... what could be the problem huh???

my session.auto_start is set to 1

though not using session_register function, i also turn on the register global feature...

what's missing..?

please help.

Posted: Tue Mar 09, 2004 2:51 am
by markl999
If you have session.auto_start set to 1 then you don't need session_start() otherwise it will produce a 'Notice'.
What's the value of your session.save_path in php.ini? And what OS are you running on, windows, *nix etc ?

session variable cannot exist betwen pages.

Posted: Tue Mar 09, 2004 3:01 am
by victor
session.save_path = /tmp what should be the value..? I'm using Windows XP.. with apache server.

are we getting closer to the main problem?

Posted: Tue Mar 09, 2004 3:03 am
by markl999
Yeah, that's the problem, set it to c:\temp (or some other temp dir that exists) and restart apache/whatever. Should do the trick.

Posted: Tue Mar 09, 2004 3:14 am
by victor
my misery has been resolved thanks

Victor
(Singapore)

Posted: Tue Mar 09, 2004 3:29 am
by twigletmac
To save yourself these kind of headaches you should make sure that error_reporting is set to E_ALL in your php.ini and that display_errors is 1 when you are developing.

Mac