开发者

sessions not working

So I had developed a basic site, using $_SESSION superglobal variable for the logging in.

so the code basically after checking the login details are valid i store the users details into the session like so:

note I am starting the session before storing these values.

$_SESSION['myusername'] = $myusername;
$_SESSION['myuserid'] = $userid;
$_SESSION['logged_in'] = true;
$_SESSION['mystatus'] = $res['user_status'];

it all worked fine, throughout the time i made the site and tested etc.

now all of a sudden, the sessions are not working, so obviously the users cannot get access after logging in because the site is checking data which isnt in the session.

on the page I store the data like above, straight after i can use this:

echo "username".$_SESSION['myusername'];
echo "status".$_SESSION['mystatus'];

and its there. But when the user is directed to another page and i try:

<?php 

session_start();
include ('functions.php');

echo "username".$_SESSION['myusername'];
echo "status".$_SESSION['mystatus']; ....

the values aren't in the session. I have checked that the session开发者_如何学C id is the same, which it is.

This has always worked, so I am really puzzled.

somebody please help.

EDIT

request header & response header from firebug (page where session appears to be empty)

Response Headersview source
Date    Sat, 11 Jun 2011 15:18:48 GMT
Server  Apache/2.2.3 (Red Hat)
X-Powered-By    PHP/5.1.6
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma  no-cache
Content-Length  3772
Connection  close
Content-Type    text/html; charset=UTF-8


Request Headersview source
Host    students.ee.port.ac.uk
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Cookie  PHPSESSID=1jqqa2oeivq76h2vhtk4uflkv1
Authorization   Basic ZWNlNzAxNDE6cGllczRtZTIy


So it seems you have a problem with keeping your session on a second request.

Session tracking is done via cookies, you should check (with Live HTTP Headers or firebug) the real cookie content sent by the server. In this cookie check the path setting and the server name given, check as well time validity settings, if something is wrong there the browser won't send back the cookie and you'll get a new session on each request.

The web developper Toolbar contains some nice cookie tools as well, where you can display a page containing all cookies details for a given page. If the cookie receveid is not there then the browser assume this cookie is not related to this page. Most of the time a php setting is enforcing the cookie.domain setting to something other than the used DNS.


Given the fact that you haven't changed a thing in the last few weeks and that it used to work, you should check that your server didn't run out of disk space. If it did, it may create a reference to a session but might not be able to serialize the data to disk once the page has been rendered.

This could explain why outputting the $_SESSION[...] works on the same page and why the cookie is set in the response.


Check whether the session id on the second request is the same as the one on the first request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜