You are not logged in.
Pages: 1
Since I don't often visit any other forum, someone here might be able to help
I have a *very* basic web 'application' written which uses PHP sessions. For some reason, the session variable only exists in one page. Change to another and it disappears. Surely session variables are suppose to avoid this problem?
Maybe I've got something entirely wrong. Any idea?
Last edited by kourosh (2010-04-14 03:50:55)
Offline
Can you post some sample code?
Matt
"It is very difficult to educate the educated."
Offline
Well I've done a basic test:
test.php
<?php
session_save_path("/home/a7049782/public_html/films/tmp");
session_start();
$session_path = session_save_path();
$_SESSION['count']=1;
?>
<html>
<body>
<?php echo "Count=" . $_SESSION['count']; ?>
</body>
</html>
This sucessfully outputs 1
Then another page:
test2.php
<?php
if(isset($_SESSION['count']))
echo "Count=" . $_SESSION['count'];
else
echo "No variable.";
?>
Which outputs 'No variable.'
(I've also tried this without defining a path, still the same result)
Offline
You need:
session_start();
In the test2.php page before you use any session variables. For example:
<?php
session_start();
if(isset($_SESSION['count']))
echo "Count=" . $_SESSION['count'];
else
echo "No variable.";
?>
Matt
"It is very difficult to educate the educated."
Offline
Right, I tried that, doesnt work :S
I thought I would only need to start the session once, and by setting a variable in test.php, that I would be able to access it in test2.php too?
Or have I got this entirely wrong?
Offline
You need the two session_start() statements. Perhaps the problem is with the cache of the browser. Also you can check a similar example in the Official Php page (Example #1 and #2).
Offline
Pages: 1