PHP会话不工作 [英] PHP session not working

查看:134
本文介绍了PHP会话不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的我已经放弃了在这个问题上,我起了疑心破坏我的设置引起的问题,自此开创了新的服务器。我想找到这个问题会带我的时间比启动一个新的服务器,并设置它。但是我在找出仍然有兴趣是什么原因导致这个,因为它是完美的3个月运行,才开始表现出这些症状在周末。 **

I have given up on this question as I suspect something corrupted my settings causing the problems and have since then created a new server. I figured finding the problem would take me more time than starting a new server and setting it up. However I'm still interested in finding out what caused this as it was running perfectly for 3 months and only started to show these symptoms over the weekend. **

=============================================== ================================

===============================================================================

我有一点初学者的问题,可能是因为我一直在其他语言,在过去几个月,我只是似乎无法找出为什么这是行不通的。 我如下提出了一个非常简单的脚本来测试它,其中有云:

I'm having a bit of a beginner problem, probably because I've been working in other languages for the past months and I just can't seem to find out why this isn't working. I've made a very simple script to test it out, which goes as follows:

<?php session_start();
  print_r($_SESSION);
  if(isset($_SESSION['views'])){
      $_SESSION['views'] = $_SESSION['views']+ 1;
  }
  else{
      $_SESSION['views'] = 1;
  }
  echo "views = ". $_SESSION['views'];
  echo '<p><a href="">Refresh</a></p>';

  # for testing
  var_dump($_SESSION);

?>

什么情况是,在后续代码var_dump表明,会话与观点的关键和1。然而,当刷新页面没有活动的会话中价值创造和意见键值设置为1了。

What happens is that the var_dump shows that a session is created with a key of views and the value of 1. However when refreshing the page no active session is found, and the views key is set to 1 again.

现在奇怪的事情对我来说是有PHPSESSID下创建一个会话ID。我试图检查存储会话的路径是可写的,它是。是通过返回的页面的标题如下:

Now the strange thing to me is that there is a session id created under PHPSESSID. I've tried to check if the path to store the sessions in was writable and it is. The headers returned by the page are as follows:

Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public
Connection  close
Content-Encoding    gzip
Content-Length  68
Content-Type    text/html; charset=utf-8
Date    Wed, 18 Jan 2012 13:03:34 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Pragma  no-cache
Server  Apache
Vary    Accept-Encoding
X-UA-Compatible IE=Edge,chrome=1

而在请求头中的会话cookie被发送如下:

And in the request header the session cookie is send as follows:

 Cookie PHPSESSID=0e1416r7pun3pamvc7cp8mjat3

我不知道是否有什么错在那里。我在Amazon EC2上的Linux AMI运行此。

I'm not sure if there is anything wrong in there. I am running this on an Amazon EC2 linux AMI.

我还可以包括的phpinfo():

I'll also include phpinfo():

PHP Version 5.3.6
System  Linux ip-**-**-**-** *.*.**.**-**.**.amzn1.x86_64 #1 SMP Sat Feb 19 23:42:04 UTC 2011 x86_64 
session
Session Support     enabled    
Registered save handlers    files user    
Registered serializer handlers  php php_binary wddx    
Directive   Local Value Master Value    
session.auto_start  Off Off
session.bug_compat_42   Off Off
session.bug_compat_warn Off Off
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly On  Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    no value    no value
session.entropy_length  0   0
session.gc_divisor  1000    1000
session.gc_maxlifetime  1440    1440
session.gc_probability  1   1
session.hash_bits_per_character 5   5
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /var/lib/php/session    /var/lib/php/session
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

任何帮助将是很大的pciated因为我已经花了一整天来解决这个问题,但似乎无法找到解决办法AP $ P $。如果您需要了解更多信息,请让我知道。

Any help would be greatly appreciated as I've been spending all day to solve this but can't seem to find the solution. If you need any more information, please let me know.

推荐答案

您应该检查session.use_cookies在php.ini文件。

You should check session.use_cookies in your php.ini file.

响应的集管不具有COOKIE

Headers of the response doesn't have a COOKIE.

session.use_cookies已为等于1。

session.use_cookies have to be equals to 1.

这篇关于PHP会话不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆