会议正在变得疯狂。只有 Mozilla 能够处理
问题
我有一个管理面板。目前只有 Mozilla 能够处理登录。 Chrome、IE、Opera 等浏览器甚至不会显示会话中携带的任何消息,因此除了 Mozilla 之外没有人能够登录任何浏览器。
一些信息
- 我在我的服务器上使用PHP 5.3.6,在我的本地服务器上使用PHP 5.3.5 电脑。
- 我的代码是面向对象的。
ini_set("session.use_only_cookies", 1);
和ini_set('session.cookie_secure', 1);
用于构造方法 我的课程。- SLL 上的此网站
登录过程:首先,我从表单中收集所有信息,验证并收集数据。验证后,如果一切正常,我会将此数据发送到我的会话类中的登录方法。
public function login ($user) {
global $siteSettings;
if ($user) {
$this->id = $_SESSION['id'] = $user->id;
$this->username = $_SESSION['username'] = $user->username;
$this->fullName = $_SESSION['fullName'] = $user->fullName;
$this->group_id = $_SESSION['group_id'] = $user->group_id;
$this->groupName = $_SESSION['groupName'] = $user->groupName;
$this->lastLogin = $_SESSION['lastLogin'] = $user->lastLogin;
$this->isAdmin = $_SESSION['isAdmin'] = ($user->admin == 1) ? true : false;
$this->isAgent = $_SESSION['isAgent'] = ($user->agent == 1) ? true : false;
self::$language = $_SESSION['language'] = ($user->language != "" || $user->language != NULL) ? $user->language : self::$language;
if ($user->language != "" || $user->language != NULL) {
$_SESSION['language'] = $user->language;
}else {
if (!defined(DEFAULT_LANGUAGE)) {
$browserLang = "|".$_SERVER["HTTP_ACCEPT_LANGUAGE"];
$browserLang = getStringBetween($browserLang, "|","-", FALSE);
if (!file_exists(LANGUAGES.$browserLang.".php")) $browserLang = FALSE;
}
$_SESSION['language'] = ($browserLang) ? $browserLang : DEFAULT_LANGUAGE;
}
# When 2 Update session_id
$date = new DateTime("now");
$UpdateTime = $siteSettings->session->timeOut * 60;
$date->add(new DateInterval("PT".$UpdateTime."S"));
$_SESSION['SIDUpdateTime'] = $date->format("Y-m-d G:i:s");
# UPDATE LAST LOGIN & ADD SESSION ID
# Clear Fields
members::clearFields();
members::$fields['id'] = $_SESSION['id'];
members::$fields['lastLogin'] = date("Y.m.d G:i:s");
members::$fields['lastLoginIP'] = $_SERVER['REMOTE_ADDR'];
# GET THE SALT
$saltInfo = members::getData("id", "salt", members::$fields['id']);
# SETTING SESSION ID ENCRYPTION
crypt::setKey($saltInfo->salt);
members::$fields['sessionID'] = crypt::encode(session_id());
members::$fields['sessionIP'] = $_SERVER['REMOTE_ADDR'];
members::$fields['sessionAgent'] = $_SERVER['HTTP_USER_AGENT'];
members::save();
$this->loggedIn = true;
var_dump($_SESSION);
}
}
当我对数据进行愚蠢处理时,我可以看到 $_SESSION 有一些值。
为了测试它,我停止了脚本,在 var_dump($_SESSION);
(添加 die();
)之后我创建了 test.php 文件并尝试了这个;
<?php
ob_start();
session_start();
echo '<pre>';
var_dump($_SESSION);
echo '<pre>';
ob_end_flush();
?>
输出是 array(0) {}
但是当我在 Mozilla 上尝试完全相同的操作时,test.php 的输出应该是这样的(与我的会话类中登录方法的结果匹配)。
- 我在本地计算机上尝试过,但没有遇到同样的情况 问题。
- 我禁用了页面中的所有 java 脚本和 jquery 代码只是为了 我心里没有‘也许’。
- 转储数据后,脚本停止。这就是为什么
$_SESSION
变量不应更改的原因。由于某种原因,当它在服务器上时,只有 Mozilla 能够显示预期结果,而其他浏览器则显示NULL
。
此时我真的不知道该如何看待这个问题来尝试解决它。我能想到的是,这个问题可能与服务器配置有关。但是,PHP 是服务器端编程。 PHP 不应该为 Jquery、CSS、HTML 等浏览器显示不同的行为...
很抱歉,我无法提供管理面板链接。考虑到这是一个活跃的管理面板。如果有必要,我可以将其安装在另一个域上让您尝试,但我相信我上面提供的信息解释了一切。
提前感谢您的帮助。
PROBLEM
I've got an admin panel. Currently only Mozilla is able to process log ins. Browsers like Chrome, IE, Opera won't even show any message carried through sessions thus no one is able to log in any browser but Mozilla.
SOME INFORMATION
- I'm using PHP 5.3.6 on my server, PHP 5.3.5 on my local
computer. - My code is Object Oriented.
ini_set("session.use_only_cookies", 1);
andini_set('session.cookie_secure', 1);
are used in construction method
of my session class.- This website on SLL
Login process: First I gather all information from form, validate and gather data. After validation if everything is right, I send this data to login method in my session class.
public function login ($user) {
global $siteSettings;
if ($user) {
$this->id = $_SESSION['id'] = $user->id;
$this->username = $_SESSION['username'] = $user->username;
$this->fullName = $_SESSION['fullName'] = $user->fullName;
$this->group_id = $_SESSION['group_id'] = $user->group_id;
$this->groupName = $_SESSION['groupName'] = $user->groupName;
$this->lastLogin = $_SESSION['lastLogin'] = $user->lastLogin;
$this->isAdmin = $_SESSION['isAdmin'] = ($user->admin == 1) ? true : false;
$this->isAgent = $_SESSION['isAgent'] = ($user->agent == 1) ? true : false;
self::$language = $_SESSION['language'] = ($user->language != "" || $user->language != NULL) ? $user->language : self::$language;
if ($user->language != "" || $user->language != NULL) {
$_SESSION['language'] = $user->language;
}else {
if (!defined(DEFAULT_LANGUAGE)) {
$browserLang = "|".$_SERVER["HTTP_ACCEPT_LANGUAGE"];
$browserLang = getStringBetween($browserLang, "|","-", FALSE);
if (!file_exists(LANGUAGES.$browserLang.".php")) $browserLang = FALSE;
}
$_SESSION['language'] = ($browserLang) ? $browserLang : DEFAULT_LANGUAGE;
}
# When 2 Update session_id
$date = new DateTime("now");
$UpdateTime = $siteSettings->session->timeOut * 60;
$date->add(new DateInterval("PT".$UpdateTime."S"));
$_SESSION['SIDUpdateTime'] = $date->format("Y-m-d G:i:s");
# UPDATE LAST LOGIN & ADD SESSION ID
# Clear Fields
members::clearFields();
members::$fields['id'] = $_SESSION['id'];
members::$fields['lastLogin'] = date("Y.m.d G:i:s");
members::$fields['lastLoginIP'] = $_SERVER['REMOTE_ADDR'];
# GET THE SALT
$saltInfo = members::getData("id", "salt", members::$fields['id']);
# SETTING SESSION ID ENCRYPTION
crypt::setKey($saltInfo->salt);
members::$fields['sessionID'] = crypt::encode(session_id());
members::$fields['sessionIP'] = $_SERVER['REMOTE_ADDR'];
members::$fields['sessionAgent'] = $_SERVER['HTTP_USER_AGENT'];
members::save();
$this->loggedIn = true;
var_dump($_SESSION);
}
}
When I dumb the data I can see $_SESSION got some values.
Just to test it, I stopped the script where after var_dump($_SESSION);
(added die();
) I created test.php file and tried this;
<?php
ob_start();
session_start();
echo '<pre>';
var_dump($_SESSION);
echo '<pre>';
ob_end_flush();
?>
Output is array(0) {}
But when I try exactly the same thing with Mozilla, output of test.php is the way it should be (matching with login method's result in my session class).
- I have tried from my local computer and I don't experience the same
problem. - I disabled all java script and jquery codes from the page just to
have no 'maybe' in my mind. - After dumping the data, script is stopped. That's why
$_SESSION
variable shouldn't change. For some reason when it is on the server only Mozilla is able to show expected result while other browsers showsNULL
.
At this point I really don't know what to think of about this problem to try to solve it. All I can think of is, this problem is possibly related to server configuration. But then, PHP is server side programming. PHP shouldn't display different behavior for browsers like Jquery, CSS, HTML...
I'm sorry, I can't provide admin panel link. Considering this is an active admin panel. If necessary I could install it on another domain to let you try but I believe the information I gave above explains everything.
Thank you for your help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有一个类似的问题...只需启用cookie..以便在登录后将执行设置会话的代码并设置会话。可能是会话无法设置...
还要检查此 http: //php.net/manual/en/function.session-cache-limiter.php
I had a similar problem... just enable the cookies.. so that after login the code to set the sessions will be executed and the sessions will be set. may be the sessions r not able to set...
also check this http://php.net/manual/en/function.session-cache-limiter.php
如果大的东西不起作用,请将其缩小,测试并重新设计。调试,并从那里构建。
这有效吗? (运行两次)。
如果这在所有浏览器中都有效,则与您的代码有关。例如,空会话可能与无法写入的 cookie 有关。还将错误报告设置为 E_ALL | E_STRICT,所以你会看到所有出错的地方。
If something large doesn't work, trim it down, test & debug, and build up from there.
Does this work? (Run it twice).
If this works in all browsers, it's got something to do with your code. An empty session might have something to do with a cookie that can't be written, for example. Also set error reporting to E_ALL | E_STRICT, so you'll see everything that goes wrong.
事实证明,Mozilla FireFox 能够处理一些数据,但我尝试过的其他浏览器却不能,因此它们会在每次页面加载时重置整个会话。
我的本地计算机没有问题,但在服务器上我遇到了会话问题。我不知道为什么
session_set_cookie_params();
和setcookie();
在服务器上不起作用,所以我不得不编写更长的版本;用上面的代码替换我的方法解决了问题。
感谢大家的时间、关心和兴趣。
It turns out Mozilla FireFox is able to process some data but other browsers I tried with are not and therefore they reset the whole session with each page load.
I had no problem with my local computer but on the server I had sessions problem. I don't know why
session_set_cookie_params();
andsetcookie();
didn't work on the server so I had to code longer version;Replacing my method with the code above solved the problem.
Thank you all for your time, concern and interest.