Session looses its data

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
NWSolutions
Forum Newbie
Posts: 1
Joined: Thu Feb 08, 2007 7:52 am

Session looses its data

Post 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!
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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,
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

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

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