PHP: Session files contain no data
I've looked around on the internet, including stack overflow, for a few days trying to resolve my issue with PHP sessions. For one, I've noticed that most of the tutorials simply say "Here's the code, go use it." and not so much "This is how it works." Additionally, all of the issues/answers I find seem to be about information being lost on refresh or after switching pages and none of these apply to me.
The data in $_SESSION is being stored/loaded no matter which page I view. My issue is, when I view the session files on the server, there is no data in them. Additionally, when I destroy a session or unset the variables the information is still stored and the next time $_SESSION is accessed the old information is retrieved.
To troubleshoot the behavior of sessions on my server I created an extremely simple script:
<?p开发者_如何学JAVAhp
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
echo $_SESSION['count'];
?>
This is ALL of the code on the page (viewable here: ). Every time this page is refreshed a new, blank, session file is saved into the specified directory on the server and the counter does not increase.
More information:
For information regarding php install: Hosted on GoDaddy Shared Hosting - Linux OS I will update the permissions on the phpsessions directory to be temporarily browseable shortly. ()You need to call session_start()
before you try to use the session.
You have to start your session using session_start()
Not only once in every page you use sessions make sure to have session_start()
Like this:
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
echo $_SESSION['count'];
?>
UPDATE: I haven't been to stack overflow in a while and decided to look back at this question because it was 1 of the only 2 I asked. I'd like to mention that the issue was that the php session name was changed and needed to be changed back to the default.
精彩评论