Jump to content

[SOLVED] Sessions not working at all


raytri

Recommended Posts

I'm trying to get sessions to work, and having no luck.

 

Here's the code for the test pages I built:

 

Page 1 (test.php):

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
session_start();

$_SESSION['username']= "testusername";

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
echo '<p>This is a test of the Sessions function. The username is '.$_SESSION['username'].'.</p><a href="test2.php">Go to page 2</a>';

?>

</body>
</html>

 

Page 2 (test2.php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
session_start();
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
echo '<p>This is a test of the Sessions function. The username is '.$_SESSION['username'].'.</p><a href="test.php">Go to page 1</a>';

?>

</body>
</html>

 

The output for the first page is what I would expect:

 

This is a test of the Sessions function. The username is testusername.

 

But the output for the second page loses the variable:

 

This is a test of the Sessions function. The username is .

 

When I echo the SID for each page, it shows that it's generating a new session for each page.

 

Suggestions?

 

In case it matters, this is running on an Apache server, I'm testing in Firefox and Safari, and the site is not in the top-level folder in the domain; it's in the "test" folder in my domain (where I build things prior to transferring them to the client's domain).

 

 

Link to comment
https://forums.phpfreaks.com/topic/147965-solved-sessions-not-working-at-all/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.