Page 1 of 1

Session variables not saving in Windows 2003 Server

Posted: Fri Feb 02, 2007 2:05 pm
by joshmaker
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm moving a website I built onto a Windows 2003 Server onto which I have installed PHP.  However, the session variables are not being saved from page to page.  Here is the code from the first test page I built:

Code: Select all

<?php
session_start();

session_register("level");

$_SESSION["level"] = 42;
print 'Session: '.$_SESSION["level"];
?>

<br />
<a href="sessiontest.php">session test</a>
As you would expect, this page prints out "Session: 42" followed by a link to the second test page. Here is the code for that page

Code: Select all

<?php
session_start();

print 'Session: '.$_SESSION["level"];
?>
When I follow the link however, this page only prints out "Session: " -- the variable "level" seems to have been lost. I've checked my php.ini file to ensure that session.auto_start = 0 and now I am out of ideas. Does anyone know if I need to change a setting in Windows or if there is a different bit of code I should use?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Feb 02, 2007 10:39 pm
by feyd
session_register() and $_SESSION don't mix well. Remove the former.

Posted: Mon Feb 05, 2007 1:44 pm
by joshmaker
Unfortunately, I've tried it with and without "session_register("level"); " as well as using "$HTTP_SESSION_VARS" instead of "$_SESSION"... still no luck getting sessions to work.

Any other suggestions?

Posted: Mon Feb 05, 2007 2:05 pm
by volka
does

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
session_start();

if ( !isset($_SESSION['xyz']) ) {
	$_SESSION['xyz'] = array();
}

$_SESSION['xyz'][] = date('H:i:s');
?>
<html>
	<head><title>session test</title></head>
	<body>
		<p>version: <?php echo phpversion(); ?></p>
		<p>name: <?php echo session_name(); ?></p>
		<pre><?php var_export($_SESSION['xyz']); ?></pre>
		<p>name: <?php echo $_SESSION['test']; ?></p>
		<a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload</a>
	</body>
</html>
work?

Problem fixed

Posted: Mon Feb 05, 2007 2:13 pm
by joshmaker
I created a new folder called "sessions" and pointed the session variables to be saved there in the php.ini file (session.save_path="C:\Program Files\PHP\sessions") , and then I fiddled with the folder permissions until it worked.

Thanks to everyone who replied!