Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SESSION values not being passed (PHP 5.1.2)

Status
Not open for further replies.

maslett

Technical User
Mar 11, 2004
121
GB
Hi, I'm having major problems getting $_SESSION variables to work on my web server. They don't keep their values. I've written some simple scripts to show the problem.

Script1 - sets the session variable
Code:
<php?
session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>session test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<?php
$_SESSION['testvar']="test value";
echo "session testvar=".$_SESSION['testvar'].'<br>';
print_r($_SESSION);
?>
<br>blah1
</body>
</html>

Script 1 output:
Code:
session testvar=test value
Array ( [testvar] => test value )
blah1

and script 2 displays the variable (it should but it doesn't)
Code:
<php?
session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>session test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<?php
echo "session testvar=".$_SESSION['testvar'].'<br>';
print_r($_SESSION);
?>
<br>blah2
</body>
</html>

Script2 output - the SESSION value is blank?!:
Code:
session testvar=

blah2

You can see my phpinfo()here (unsafe - I know):
link

I'm really pulling my hair out over this!

Cheers.
 
More info:

After a bit of research I checked the session.save_path - (/var/lib/php5) it was owned by root. I changed the owner and chmod'd it 777 but I still get the same problem.
 
script two should not work. your php opening tags are wrong. if you correct them (<?php) does the session then start properly?
 
Ah pants. I was so sure I hadn't cocked up.

I did.

You're right - it works. I feel such a numtpy.

Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top