Hello. I'm fairly new to session handling in PHP. I've simplified the behavior I'm seeing to two PHP scripts. You can view the behavior firsthand here .
Basically, sess1.php starts a session and initializes a session variable. Then, it links to sess2.php, which tries to access the session variable. Please see code below:
Can anyone tell me what I'm missing here?
By the way, Yahoo webhosting is hosting my site and they're running PHP v 4.1.2. You can view the phpinfo() of Yahoo.
sess1.php
<?
session_start();
$_SESSION['var1'] = "hello";
?>
<html>
<head><title>sess1.php</title></head>
<body>
<?
if (isset($_SESSION['var1']))
echo "Session variable var1 has been set to " . $_SESSION['var1']. "<br>";
?>
<a href="sess2.php">Go to sess2.php</a>
</body>
</html>
-------------------------------------------
sess2.php
<?
session_start();
?>
<html>
<head><title>sess2.php</title></head>
<body>
<?
if (isset($_SESSION['var1']))
echo "Session variable var1 is " . $_SESSION['var1'];
else
echo "no session registered";
?>
</body>
</html>
------------------------------------------