Hi, I’m new to sessions. I thought I’d got the idea after reading a few articles, but I just can’t get my code to work!!
As the site I was trying to use them with is complicated enough, I thought I’d try and make a really simple example of what I want to do and I can’t even get that to work…
On one page, I have the code:
[code=php]<?php
session_start();
$_SESSION[‘test’] = ‘hello world’;?>
<head>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
</head>
<body>
<?php echo $_SESSION[‘test’]; ?>
<br />
<a href=”test.php”>test.php</a>
</body>
</html>
which seems to work fine… it displays the hello world text, etc. But the linked file, when it tries to call the variable, gives the error
[quote]
Notice: Undefined variable: _SESSION in xxxxxx
here’s the code for the second page:
[code=php]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
</head>
<body>
<?php
error_reporting(E_ALL);
echo $_SESSION[‘test’]; ?>
</body>
</html>
I tried it on my localhost and on two different web servers, which just confirmed that it is my code at fault not my server!! Can someone please tell me what I’m doing wrong?
Thanks