NAT防火墙/路由器背后的_SESSION怪异:bug? [英] _SESSION weirdness behind a NAT firewall/router: bug?

查看:112
本文介绍了NAT防火墙/路由器背后的_SESSION怪异:bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我发现了一个PHP错误,请告诉我。


我坐在家里网络上的几台电脑前面,后面是

a NAT防火墙/路由器。我在这些不同的b
计算机上测试我的网站(运行不同的浏览器,以不同的用户身份登录,

等)。我的网站通过使用

$ _SESSION跟踪用户登录。


这里奇怪的是:所有计算机都已注销,然后我用一台计算机将我的网站登录到我的网站 - 当我从另一台计算机浏览我的网站时,它的行为就像登录一样!如果我使用

一台计算机注销,所有其他计算机的行为就好像记录了

off!这也发生在不同的浏览器(比如IE和Opera)

在同一台机器上运行。


这是特别严重的,因为我有四类用户:

非登录访客,登录用户,付费客户,以及

超级用户。例如,以超级用户身份登录,为我的家庭网络上的所有计算机提供超级用户

权限!


AAAARRRGH !!我无法理解这一点。似乎$ _SESSION是* b $ b使用*我的IP地址,并且没有来自我网络浏览器的唯一识别信息

。这是一个php错误吗?


背景:


基本上我正在做的事情。所有脚本首先包含一个

require_once()指令,该指令包含一个文件,该文件预先执行

后面的语句:


session_save_path(" / home / mydomain / public_html / lists");

session_name(''login_settings'');

session_start();


(当然,保存路径存在,它包含会话数据

文件。)然后,每个脚本调用一个函数isLoggedOn()来确定
确定登录的用户类型,如果有的话:


函数isLoggedOn()

{

if(isset($ _ SESSION [ ''超级用户'']))

返回''超级用户'';

if(isset($ _ SESSION [''customer'']))

返回''customer'';

if(isset($ _ SESSION [''user'']))

返回''user'';

返回NULL; //未注册或未登录

}


从isLoggedOn()收到返回值后,脚本

完全表现出来它应该取决于用户的类型

登录。$ _SESSION [''user''],$ _SESSION [''customer'']的价值,

和$ _SESSION [''超级用户'']是MySQL表中用户的ID,用户类型为

;这个值是由login.php脚本设置的。


我有三个login.php脚本:对于普通用户,客户和

超级用户。每个login.php脚本查询相应的数据库

以获取用户ID和密码,然后设置一些$ _SESSION值。

这里,例如,$ _SESSION会发生什么当普通用户

登录时。请注意,它确保在登录时未设置客户和超级用户类型




if($ sql-> rows){

$ userid = $ sql-> GetValue(''id'');

if($ userid){

$ _SESSION [''user''] = $ userid;

if(isset($ _ SESSION [''admin'']))

未设置($ _ SESSION [''customer'']);

if(isset($ _ SESSION [''superuser'']))

unset($ _ SESSION [''超级用户'']);

标题("位置:http://www.example.com/userindex.php");

}其他标题(位置:http://www.example.com/login.php?error = 1")

}其他标题("位置:http://www.example.com/ login.php?error = 1")


退出shou不要让先前的用户留下任何东西,

删除所有$ _SESSION数据,终止会话cookie,最后

调用session_destroy()。所以这里是我所有

用户类型的logout.php脚本。它似乎确实有用:


$ CookieInfo = session_get_cookie_params();

$ _SESSION = array(); //取消设置所有会话值


if((空($ CookieInfo [''domain'']))&&(空($ CookieInfo [''secure'']] )))

setcookie(session_name(),'''',time() - 3600,$ CookieInfo [''path'']);

elseif(空($ CookieInfo [''secure'']))

setcookie(session_name(),'''',time() - 3600,$ CookieInfo [''path''],
$ CookieInfo [''domain'']);

else

setcookie(session_name(),'''',time() - 3600, $ CookieInfo [''path''],

$ CookieInfo [''domain''],$ CookieInfo [''secure'']);

unset($ _COOKIE [session_name()]);

session_destroy();


我的机智已经结束,几乎准备管理我自己cookie和转储

这个PHP会话处理的东西。我宁愿不要;我喜欢

将一个会话cookie与敏感数据存储在

服务器上。 *如果我从家庭网络上的不同计算机同时登录它们,则其他*网站不会这样做。 MY网站有什么错误?b $ b错误?


-Alex

解决方案

_SESSION。


这是奇怪的事情:所有电脑都已注销,然后我用一台电脑记录了我的网站
- - 当我从

另一台计算机浏览我的网站时,它的行为就像登录一样!如果我使用

一台计算机注销,所有其他计算机的行为就好像记录了

off!这也发生在不同的浏览器(比如IE和Opera)

在同一台机器上运行。


这是特别严重的,因为我有四类用户:

非登录访客,登录用户,付费客户,以及

超级用户。例如,以超级用户身份登录,为我的家庭网络上的所有计算机提供超级用户

权限!


AAAARRRGH !!我无法理解这一点。似乎


_SESSION是

使用*我的IP地址,没有唯一的识别信息

来自我网络上的浏览器。这是一个php错误吗?


背景:


基本上我正在做的事情。所有脚本首先包含一个

require_once()指令,该指令包含一个文件,该文件预先执行

后面的语句:


session_save_path(" / home / mydomain / public_html / lists");

session_name(''login_settings'');

session_start();


(当然,保存路径存在,它包含会话数据

文件。)然后,每个脚本调用一个函数isLoggedOn()来确定
确定登录的用户类型,如果有的话:


函数isLoggedOn()

{

if(isset(

_SESSION [''超级用户'']))

返回''超级用户'';

if(isset(


Someone please tell me if I''ve discovered a PHP bug.

I''m sitting in front of several computers on my home network, behind
a NAT firewall/router. I am testing my web site on these different
computers (running different browsers, logged in as different users,
etc.). My web site keeps track of users logged in through the use
of $_SESSION.

Here''s the bizarre thing: All computers are logged off, then I log
into my web site with one computer -- and when I browse my site from
another computer it behaves as if logged in! And if I log off with
one computer, all other computers subsequently behave as if logged
off! This happens also with different browsers (say IE and Opera)
running on the same machine.

This is especially serious because I have four classes of users:
non-logged-in visitor, logged-in user, paying customer, and
superuser. Logging in as superuser, for example, gives superuser
privileges to ALL computers on my home network!

AAAARRRGH!! I can''t figure this out. It seems that $_SESSION is
using *only* my IP address and no unique identifying information
from the browsers on my network. Is this a php bug?

Background:

Here is basically what I''m doing. All scripts first contain a
require_once() directive that includes a file which executes the
following statements right up front:

session_save_path("/home/mydomain/public_html/lists");
session_name(''login_settings'');
session_start();

(Naturally, the save path exists, and it contains session data
files.) Then, each script calls a function isLoggedOn() to
determine the type of user logged in, if any:

function isLoggedOn()
{
if (isset($_SESSION[''superuser'']))
return ''superuser'';
if (isset($_SESSION[''customer'']))
return ''customer'';
if (isset($_SESSION[''user'']))
return ''user'';
return NULL; // unregistered or not logged in
}

Upon receiving the return value from isLoggedOn(), the script
behaves exactly the way it should depending on what type of user is
logged in. The value of $_SESSION[''user''], $_SESSION[''customer''],
and $_SESSION[''superuser''] is the user''s ID in the MySQL table for
that user type; the value is set by a login.php script.

I have three login.php scripts: for normal users, customers, and
superuser. Each login.php script queries the appropriate database
for user ID and password, and then sets some $_SESSION values.
Here, for example, is what happens with $_SESSION when a normal user
logs in. Note that it ensures that the customer and superuser types
are unset upon this login:

if ($sql->rows) {
$userid = $sql->GetValue(''id'');
if ($userid) {
$_SESSION[''user''] = $userid;
if (isset($_SESSION[''admin'']))
unset($_SESSION[''customer'']);
if (isset($_SESSION[''superuser'']))
unset($_SESSION[''superuser'']);
header("Location: http://www.example.com/userindex.php");
} else header("Location: http://www.example.com/login.php?error=1")
} else header("Location: http://www.example.com/login.php?error=1")

Logging off shouldn''t leave anything behind from prior users,
deleting all $_SESSION data, killing the session cookie, and finally
calling session_destroy(). So here''s my logout.php script for all
user types. It does seem to work correclty:

$CookieInfo = session_get_cookie_params();
$_SESSION = array(); // unset all session values

if ((empty($CookieInfo[''domain''])) && (empty($CookieInfo[''secure''])))
setcookie(session_name(), '''', time()-3600, $CookieInfo[''path'']);
elseif (empty($CookieInfo[''secure'']))
setcookie(session_name(), '''', time()-3600, $CookieInfo[''path''],
$CookieInfo[''domain'']);
else
setcookie(session_name(), '''', time()-3600, $CookieInfo[''path''],
$CookieInfo[''domain''], $CookieInfo[''secure'']);
unset($_COOKIE[session_name()]);
session_destroy();

I''m at my wit''s end, almost ready to manage my own cookies and dump
this PHP session handling stuff. I''d rather not though; I like
having the one session cookie with sensitive data stored on the
server. *Other* sites don''t behave this way if I log into them
simultaneously from different computers on my home network. What''s
wrong with MY site??

-Alex

解决方案

_SESSION.

Here''s the bizarre thing: All computers are logged off, then I log
into my web site with one computer -- and when I browse my site from
another computer it behaves as if logged in! And if I log off with
one computer, all other computers subsequently behave as if logged
off! This happens also with different browsers (say IE and Opera)
running on the same machine.

This is especially serious because I have four classes of users:
non-logged-in visitor, logged-in user, paying customer, and
superuser. Logging in as superuser, for example, gives superuser
privileges to ALL computers on my home network!

AAAARRRGH!! I can''t figure this out. It seems that


_SESSION is
using *only* my IP address and no unique identifying information
from the browsers on my network. Is this a php bug?

Background:

Here is basically what I''m doing. All scripts first contain a
require_once() directive that includes a file which executes the
following statements right up front:

session_save_path("/home/mydomain/public_html/lists");
session_name(''login_settings'');
session_start();

(Naturally, the save path exists, and it contains session data
files.) Then, each script calls a function isLoggedOn() to
determine the type of user logged in, if any:

function isLoggedOn()
{
if (isset(


_SESSION[''superuser'']))
return ''superuser'';
if (isset(


这篇关于NAT防火墙/路由器背后的_SESSION怪异:bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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