Page 1 of 1

Session looses its data

Posted: Thu Feb 08, 2007 8:18 am
by NWSolutions
Hi,
this is not the first time I'm working with PHP sessions, but I'm a bit puzzled.

Right now I'm working on a project for somebody who's webspace has PHP Version 4.4.4 (1and1.com hosting).
The sessions dont behave as expected.

session_id() gives me steady ids - thats ok.

It's possible to add data into $_SESSION array and use them.
E.g. $_SERVER[xy] = $_POST[xy] - is no problem.

But with the next call to another page or the same page the data is gone.
Like Preview-Page --> Result.page


I tried a couple of ini_set("session.use_cookies", "1") a.so. but result is the same - or it seems so.

Does anybody have an idea?


Here a link to the phpinfo: http://www.eifelstuff.com/phpinfo.php


THANKS!

Posted: Thu Feb 08, 2007 8:25 am
by impulse()
I had a similar problem where sometimes a page which included sessions would work sometimes and then not on others.
It turned out to be that the page hadn't got

Code: Select all

session_start();
at the top of the page. So when I went to a page that had session_start(); set correctly it would make the other page work temporarily then stop as soon as the session stopped.

Hope that helps,

Posted: Thu Feb 08, 2007 8:26 am
by Ollie Saunders
is it possible? Well I should hope so because that's the whole idea behind sessions :)

Are you calling session_start() at the top of all the scripts that are setting and getting the $_SESSION vars.

Posted: Thu Feb 08, 2007 8:34 am
by volka
please try

Code: Select all

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

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

$_SESSION['xyz'][] = date('H:i:s');
?>
<html>
	<head><title>session test</title></head>
	<body>
		<a href="<?php echo $_SERVER['PHP_SELF']; ?>">reload</a>
		<pre>session: <?php var_export($_SESSION); ?></pre>
	</body>
</html>
does it show more than one value in _SESSION when you reload the page?