PHP会话无法正常工作 [英] PHP session is not working

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

问题描述

我正在使用wamp2.0 - PHP 5.3,apache 2.2.11,但我的会话不存储数据。

I am working with wamp2.0 - PHP 5.3, apache 2.2.11 but my sessions are not storing data.

我有一个接受参数的页面,哪个(简化版)我想在会话中存储,所以当我来到

I have a page that accepts a parameter, which (simplified version) I wanna store in a session, so when I come to

http://www.example.com/home.php?sessid=db_session_id

脚本如下:

session_start();

$sessid = @$_GET['sessid'];
if ($sessid) {
  $_SESSION['sessid'] = $sessid;
}
var_dump($_SESSION);

和输出:

array(1) { [0]=> string(13) "db_session_id" } 

这很好,但是当我去链接(没有sessid参数) $ _ SESSION 数组是空的。我的事件试图在没有参数的页面之前评论 $ _ SESSION ['sessid'] = $ sessid; 行,但它仍然没有用。

which is fine, but then, when I go to link (without the sessid parameter) the $_SESSION array is empty. I've event tried to comment the $_SESSION['sessid'] = $sessid; line before going to the page without the parameter, but still it didin't work.

我检查了 session_id()输出,会话ID保持不变。

I've checked the session_id() output and the session id remains the same.

phpinfo()的会话设置

Session settings from phpinfo()

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   On  On
session.bug_compat_warn On  On
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off 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   c:/wamp/tmp c:/wamp/tmp
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

编辑:


会话被iframe删除。我不知道为什么,但是当
评论时,会话工作正常。事实上,iframe必须保持
(当然这很糟糕,但我对此无能为力)。
嗯...你知道任何使用iframe让会话工作
的变通办法吗?

The sessions are deleted by an iframe. I don't know why, but when commented, the sessions work fine. Thing is, the iframe has to stay there (which of course is bad, but I can't do anything about it). Well...do you know about any workarounds to get the sessions working with an iframe?


推荐答案

只有当帧相对于同一个域时,才能访问该会话。例如:

A frame can access the session only if it's relative to the same domain. For example:

<? 
$_SESSION["foo"]="foo"; 
?><html> 
 <body> 
  <iframe src ="test.php" width="200" height="200"></iframe> 
 </body> 
</html> 
<? 
print_r($_SESSION); 
?>

应该在iframe外部和内部工作。如果您仍然遇到问题,请尝试:

Should work outside and inside the iframe. If your still having problems try:

 <?php  session_start();

    $sessid = $_GET['sessid'];
    if (isset($sessid) && $sessid != "" && $sessid != NULL) {
      $_SESSION['sessid'] = $sessid;
    }
    print_r($_SESSION);?>

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

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