简体   繁体   English

php 5.3中的$ _SESSION变量不粘

[英]$_SESSION variables in php 5.3 not sticking

In a server upgrade from 5.2.17 to 5.3.13 my $_SESSION variables are no longer being passed from page to page. 从5.2.17升级到5.3.13的服务器中,我的$ _SESSION变量不再从页面传递到页面。

In page 1, I'm setting $_SERVER["isLoggedIn"] = true and in page 2 I'm testing, but find all $_SESSION variables are unset. 在第1页中,我设置$ _SERVER [“ isLoggedIn”] = true,在第2页中,我正在测试,但是发现所有$ _SESSION变量都未设置。

I've cut down the code for a simple example as follows: login.html: 我将代码简化为一个简单的示例,如下所示:login.html:

<?php
session_start();
    $_SESSION["isLoggedIn"] = true;
    $_SESSION['visitorLanguage']  = "en" ; 


    if ($_SESSION["isLoggedIn"]  == true ){
        print "<p> Log in successful. </p>";
        print "<script>window.location='index.html? lang=".$_SESSION['visitorLanguage']." '</script>";
        }

?>

index.html: index.html:

<?
session_start();
echo "Version: ".phpversion(); 
echo " Session Data: "; 
echo "Is logged in: " . $_SESSION["isLoggedIn"]. "<br/>";
echo "Visitor Language: " . $_SESSION["visitorLanguage"];
?>

Returns: 返回值:

Version: 5.3.13 Session Data: Is logged in: 
Visitor Language
and in 5.2:
Version: 5.2.17 Session Data: Is logged in: 1
Visitor Language: en

与此类似的问题只花了我3天的时间,请确保注释掉request_order = None或在php.ini中将其设置为“ GPCS ”,否则会话变量将不会添加到超级全局数组REQUEST中。

As I understand it, a page that doesn't have a name ending in .php should not go to the php processor at all. 据我了解,没有以.php结尾的名称的页面根本不应该进入php处理器。 It is more of a mystery that it works in 5.2 than that it does not work in 5.3. 在5.2中工作而不是在5.3中工作更是一个谜。 In short, make your index page index.php, be sure to delete index.html on the server (and also locally, you do not want it getting uploaded again)... and all should be well. 简而言之,将索引页面设置为index.php,请确保删除服务器上的index.html(以及在本地,也不想再次将其上传)...,一切应该很好。 To answer your question, an installation of 5.2 is one installation and an installation of 5.3 is some other installation. 要回答您的问题,安装5.2是一个安装,安装5.3是其他安装。 One may be set up with different options to the other. 一个可能设置有与另一个不同的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM