session variable cannot exist betwen pages.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

session variable cannot exist betwen pages.

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

session variable cannot exist betwen pages.

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ?
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

session variable cannot exist betwen pages.

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

Post by victor »

my misery has been resolved thanks

Victor
(Singapore)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply