Click to See Complete Forum and Search --> : [Resolved] Session variable not registering
ywickham
08-14-2004, 10:03 AM
I'm testing an example script:
<?php
session_start();
// If session variable doesnt exist, register it
if ( !isset ( $_SESSION['test'] ) ) {
$_SESSION['test'] = 'Hello World!';
echo ( '$_SESSION[\'test\'] is registered.<br />Please refresh page' );
} else {
// Its registered so display it
echo ( '$_SESSION[\'test\'] = '.$_SESSION['test'] );
}
?>
According to what I'm seeing and reading, the first time the page displays, I should get the following result (which I do):
$_SESSION['test'] is registered.
Please refresh page
Upon refreshing the browser, I should get (which I don't):
$_SESSION['test'] = Hello World!
When I refresh the browser, I end up getting the first result over and over again. What am I missing?
Thanks!
yelvington
08-14-2004, 10:58 AM
Your example is not even parseable due to string quotation craziness -- please post your actual code.
ywickham
08-14-2004, 11:00 AM
I'm trying to post the code, but I can't get the forum to show my escape slashes. When I edit the original forum post, the code is as it should be, but it is not appearing that way when displayed.
I will continue to try and get the forum to display my code correctly.
ywickham
08-14-2004, 11:15 AM
Here is the code as I have it above (but is not displaying, for some reason):
<?php
session_start();
// If session variable doesnt exist, register it
if ( !isset ( $_SESSION['test'] ) ) {
$_SESSION['test'] = 'Hello World!';
echo ( '$_SESSION[\\'test\\'] is registered.<br />Please refresh page' );
} else {
// Its registered so display it
echo ( '$_SESSION[\\'test\\'] = '.$_SESSION['test'] );
}
?>
yelvington
08-14-2004, 11:53 AM
I don't see anything that would cause a problem. I made a slightly different version
<?php
session_start();
// If session variable doesnt exist, register it
if ( !isset ( $_SESSION['test'] ) ) {
$_SESSION['test'] = 'Hello World!';
echo $_SESSION['test'], ' is registered.<br />Please refresh page' ;
} else {
// Its registered so display it
echo '$_SESSION[test] = ' , $_SESSION['test'];
}
?>
and it worked just fine. So I would check to make certain that the session save path is correctly set in php.ini. PHP5 has a way of defaulting to nonsense, regardless of what the notes in php.ini might say. Be sure to set everything explicitly.
ywickham
08-14-2004, 12:00 PM
Thank you for your help.
Someone else manages our server, so, are you saying that I basically need to ask them to make sure that whatever path is specified in the php.ini file for the "session.save_path" directive is a writeable directory? (Did that make sense? :bemused: )
yelvington
08-14-2004, 12:11 PM
That's correct.
When I upgraded to PHP5, I had to spend quite a bit of time tracking down little ini file incompatibilities like this.
ywickham
08-14-2004, 12:21 PM
Thank you. I wanted to make sure I knew what I was talking about before I asked them to do it. :p
I appreciate all your help.
ywickham
08-16-2004, 10:24 AM
I got a reply from our web host and it seems that I left out some pertinent information in this problem.
This PHP code is called as a SSI from an HTML page. I thought that including the file at the top of the HTML page, it would still pick up the session file. That doesn't look like the case.
If I'm calling the file from an SSI like above, is there any way to get the PHP files to pick up the session file with the variables?
yelvington
08-16-2004, 10:26 AM
Does it process any PHP in the include?
ywickham
08-16-2004, 10:29 AM
I'm going to say yes, it does, since it displays the output of the script as if it was the first time the page was loaded.
ywickham
08-17-2004, 11:54 AM
I'm closing this thread because my initial question has been answered and my remaining question has evolved into something else. I am opening a new thread.
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.