基于PHP的会话变量不保留值.适用于localhost,但不适用于服务器

Foo*_*Foo 5 php

我一直试图调试这个问题好几个小时,但无济于事.我已经使用PHP很多年了,经过长时间的中断后又回到了它,所以我仍然有点生疏.

无论如何,我的$ _SESSION变量并没有因为某些我无法弄清楚的原因而保留它们的价值.该网站完全适用于localhost,但将其上传到服务器似乎打破了它.

我检查的第一件事是PHP.ini服务器设置.一切似乎都很好.事实上,我的登录系统是基于会话的,它完美地运行.所以现在我知道$ _SESSIONS正常工作并保留了我的登录价值,我假设服务器已经设置好,问题出现在我的脚本中.

这是导致问题的代码的剥离版本.通过GET变量设置后,$ type,$ order和$ style不会被保留.用户单击链接,该链接通过GET设置变量,并且该变量将在其剩余的会话中保留.

我的逻辑是否存在一些我没有看到的问题?

<?php
require_once('includes/top.php'); //first line includes a call to session_start();
require_once('includes/db.php');

$type = filter_input(INPUT_GET, 't', FILTER_VALIDATE_INT);
$order = filter_input(INPUT_GET, 'o', FILTER_VALIDATE_INT);
$style = filter_input(INPUT_GET, 's', FILTER_VALIDATE_INT);

/*
According to documentation, filter_input returns a NULL when variables
are undefined. So, if t, o, or s are not set via URL, $type, $order and $style
will be NULL. 
*/    

print_r($_SESSION);
/* 
All other sessions, such as the login session, etc. are displayed here. After 
the sessions are set below, they are displayed up here to... simply with no value. 
This leads me to believe the problem is with the code below, perhaps?
*/


// If $type is not null (meaning it WAS set via the get method above)
// or it's false because the validation failed for some reason,
// then set the session to the $type. I removed the false check for simplicity.
// This code is being successfully executed, and the data is being stored...
if(!is_null($type))
{
    $_SESSION['type'] = $type;
}
if(!is_null($order))
{
    $_SESSION['order'] = $order;
}
if(!is_null($style))
{
    $_SESSION['style'] = $style;
}


 $smarty->display($template);

?>
Run Code Online (Sandbox Code Playgroud)

如果有人能指出我正确的方向,我会非常感激.谢谢.

Foo*_*Foo 7

难以置信的!

经过三个小时的调试,我发现了问题所在

HostGator,我不再钟爱的主机,使用register_globals ON运行默认的ini

我简直不敢相信.

所以$ type的变量被$ _SESSION ['type']覆盖,并且它们被视为相同.所以这是导致问题的服务器问题,而不是我的编码.很高兴知道,但我希望我的头发可以拉回5个小时.

我希望这可以帮助那些使用HostGator的人在路上感到困惑.