Session variables not saving in Windows 2003 Server

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
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Session variables not saving in Windows 2003 Server

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

session_register() and $_SESSION don't mix well. Remove the former.
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Problem fixed

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