简体   繁体   English

如果会话名称在两个不同的网站上相同会发生什么?

[英]What happens if session name is same on two different websites?

I have a two diff. 我有两个差异。 project on my XAMPP say it is Project1 and Project2 . 我的XAMPP上的项目说它是Project1Project2
When i login with Project1 , i check authentication and if it is successful then stored session. 当我使用Project1登录时,我检查身份验证,如果成功,则存储会话。 The session name is $_SESSION['username'] . 会话名称为$_SESSION['username']
The above process is same with Project2 . 上述过程与Project2相同。

now,to prevent direct access,i use this code(in both project): 现在,为了防止直接访问,我使用这个代码(在两个项目中):

if($_SESSION['username']=="")
{
  header("location:index.php");
}

so when i login with Project1 , i am also access Project2 (without login). 因此,当我使用Project1登录时,我也访问Project2 (无需登录)。
To prevent this, i know that if i create diff. 为了防止这种情况,我知道如果我创建差异。 session name for both project then it is solved. 两个项目的会话名称然后它被解决。

The above thing is in my local server. 上面的内容是在我的本地服务器上。 so i can create diff. 所以我可以创造差异。 session name for my all project. 我所有项目的会话名称。

But suppose my site is online and what happen if my session name is match with diff. 但假设我的网站在线,如果我的会话名称与diff匹配会发生什么。 site? 现场?
There is a millions of websites and there is a possibility that my session name is match with another website's session name.Then this might be happen that some user access my website with another website(in same browser) and he might be access my site without login. 有数百万个网站,我的会话名称有可能与其他网站的会话名称相匹配。然后,有些用户可能会使用其他网站(在同一浏览器中)访问我的网站而他可能无法访问我的网站登录。

So what happen if session is same for two diff. 那么如果两个差异的会话相同会发生什么。 website? 网站? Can user is access my website without login? 用户无需登录即可访问我的网站吗? If yes then what should i do to prevent it? 如果是,那么我应该怎么做才能防止它呢?

Thanks in advance. 提前致谢。

UPDATE UPDATE

according to @Let me see 's answer there is a possibility that if two sites are running on the same server then they may share the data. 根据@Let me see的答案是,如果两个站点在同一台服务器上运行,那么它们可能会共享数据。
So suppose the server is sharing then what should i do to prevent it? 所以假设服务器正在共享那么我应该怎么做以防止它呢?

Sessions are (usually) stored using cookies, and cookies are domain-specific. 会话(通常)使用cookie存储,而cookie是特定于域的。 So, it doesn't matter if google.com or evilhackerdomain.ru uses the same session name as your app; 因此,google.com或evilhackerdomain.ru使用与您的应用相同的会话名称无关紧要; your cookies are only readable/usable by the domains you specify. 您的cookie只能由您指定的域读取/使用。 Even in the unusual scenario that sessions are managed in some other way, it will be domain-specific. 即使在会话以其他方式管理的不寻常场景中,它也将是特定于域的。

So suppose the server is sharing then what should I do to prevent it? 所以假设服务器正在共享那么我应该怎么做以防止它呢?

To answer your follow up question. 回答你的后续问题。 You can simply name your session on a specific website using session_name() before your session_start(). 您可以在session_name()之前使用session_name()在特定网站上命名会话session_start().

session_name('PROJECT1');
session_start();

this one-liner should do it. 这个单行应该做到这一点。

Normally the sessionID of the sessions is stored in a cookie and it is related to the hostname and it can be shared by the multiple hostnames having the same domain. 通常, 会话的sessionID存储在cookie中 ,它与主机名相关,并且可以由具有相同域的多个主机名共享。 and as it is obvious that sessions are stored on the server . 并且很明显会话存储在服务器上
So there is a possibility that if two sites are running on the same server then they may share the data..Therefore you should always change the path for storing the sessions on the server for every different website 因此,如果两个站点在同一台服务器上运行,那么它们可能会共享数据。因此,您应始终为每个不同的网站更改在服务器上存储会话的路径

PHP Sessions are stored in Server. PHP会话存储在服务器中。 So there won't be any clash between same session names when you go live. 因此,当您上线时,相同的会话名称之间不会发生任何冲突。 Remember, You still have option to store your session in database, which helps you with more secutiry. 请记住,您仍然可以选择将会话存储在数据库中,这可以帮助您获得更多安全性。

Nothing will happen. 什么都不会发生。 Because the other Site uses its own database (with own session and user tables). 因为其他站点使用自己的数据库(具有自己的会话和用户表)。 It would only matter if two Sites share the same Database, same tables and same session handling. 只有两个站点共享相同的数据库,相同的表和相同的会话处理才有意义。

User cannot access without log in because of following reasons, 由于以下原因,用户无法登录而无法访问

The session data is stored on the server . 会话数据存储在服务器上 If two applications are running on the same server and the same domain name, then the possibility is there for them to share session data. 如果两个应用程序在同一服务器上运行且具有相同的域名,则可能存在共享会话数据的可能性。 Otherwise no conflicts with session values, if the domains are different. 如果域不同,则不会与会话值冲突。

I think if we use a security algorithm like MD5 to encrypt the session which you'll using to login. 我想如果我们使用像MD5这样的安全算法来加密您将用于登录的会话。 That will work without problem. 这将毫无问题地工作。 For example: 例如:

$name_session='username';
$name_session=md5(md5(md5($name_session));
$_SESSION[$name_session]="username_logged";

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

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