$_SESSION problem

A

Anonymous

Guest
Hello,

I am noticing something strange happening when I use $_SESSION object. On one page I set session, on next I display it. The problem is that too often on a second page value of my $_SESSION variable is not displayed.
Any suggestions?

sess.php
========
<?php
session_start();
$_SESSION['test'] = "HELLO";
header("Location: sess2.php");
?>

sess2.php
=========
<?php
session_start();
echo "test: " . $_SESSION['test'];
?>

/alex
 
I have noticed that problem before too. The only explaination that I can come up with is that the cookie has not yet been created on the clients computer with the session information. I would try passing the session id on the URL
 
thanks, I am new at this, so can you suggest a link where I can find more info?
 
does
Code:
$_SESSION['varname'] = value
is it same as
Code:
session_register('varname') = value

Please ans
 
That's exectly what I am using, but still causes problem. Some people suggested upgrading to a newer version of PHP, but others say that problem still exists. This problem is very strange since values of session object are lost at random. It's not easy for me to upgrade to a newer version of PHP since I am outsourcing my site at a web host, I guess I 'll try upgrading on my pc at home.

/webtekie
 
there is a problem with it but I got one of the newer versions of PHP and found a way around it, setting the var is the same way as you already did it, BUT viewing it is a little different

<?php
session_start();
$test = $_SESSION['test'];
echo "test: " . $test;
?>

that should solve the problem, tedious but works for me, same problem I had if I had some session variables that I wanted to put in with form info, make a normal var first, seems to do the trick.

use the new session info and forget $session_register, don't use it anymore, read about sessions in the new help file that comes out with PHP lot of great info in it

Godiwa
 
well for me it has worked easily as:

php1:

<?

$test="rah";
session_start();
session_register($test);
?>

PHP:
<?
session_start();
echo $test;
?>

this has always worked fine for me!!
 
Back
Top