• 0

PHP Session Data not saving.


Question

Hi all,

I'm having trouble saving data to a variable in PHP.

I have XAMPP set up on my laptop and the following code works on my machine (going to localhost), but doesnt work on my webhost (gradwell). I've doubled checked using PHPinfo that sessions are enabled on the host and they are. Unfortunately I cannot get to any error logs due to it being a remote host. Can anyone shed some light into this? many thanks

page 1

<?php
session_start(); // NEVER forget this!
$_SESSION['test'] = "donkey"; // store session data
echo "sending var to next page. currently our test var is : ". $_SESSION['test']; //retrieve data
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

</head>
<body>
<a href="test2.php">Go!</a>
</body>
</html>

page 2:

<?php
session_start(); // NEVER forget this!
echo "now we're on the second page, and our test var is : ". $_SESSION['test']; //retrieve data
?>

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Do you see a PHPSESSID cookie set in your browser, or does the URL get rewritten to contain it? If neither are set then PHP won't know what your session id is and won't be able to restore any session data.

If error reporting is turned off you might want to try placing a call to error_reporting at the top of your script. Call it with E_ALL as it's argument and you should see all manner of warnings and notices. That might help reveral why it isn't working. If not, it sounds like a server mis-configuration and you should speak to your host to find out what the problem is.

Link to comment
Share on other sites

  • 0

A few weeks ago I was having quite a similar problem as you describe. Sessions didn't work. Alltough sessions was enabled by php, as stated in phpinfo(). Luckily my development server is on a vmware workstation virtual machine, so I could easily fix my problem: the session directory wasn't writeable.

Do like DecoyDuck tells you, run your script with error reporting. If you get a write error from your session function, you should contact your hosting company and ask them to look in to this. Without error reporting on, you will never know what has hit your.

Add the following code on top of your script:

 ini_set ( 'display_errors', 'On' ); 

  • Like 2
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.