简体   繁体   English

会话适用于多个网站

[英]Sessions apply in more than one website

I have made 2 websites that use a log in system and everything works fine on both of them. 我已经制作了2个使用登录系统的网站,并且两个网站均正常运行。 The user can log in and log out of both. 用户可以登录和注销。 I am using xampp and have both websites open in Chrome in two tabs. 我正在使用xampp,并在Chrome中的两个标签中打开了两个网站。 On both websites I have the email address of the user displayed when the user logs in. The problem is when I log into website A al the switch to website B and refresh the page I am logged in on that website as well with the email address that I logged in with on website A. This address that is display also displays when there is no account associated with the apposite website. 在这两个网站上,我都有用户登录时显示的用户电子邮件地址。问题是,当我登录网站A时,又切换到网站B并刷新我在该网站上登录的页面以及电子邮件地址我在网站A上登录时使用的密码。当没有与apposite网站关联的帐户时,也会显示此显示的地址。 My question is how do restricted the session to the single website. 我的问题是如何将会话限制为单个网站。

This is the login action 这是登录操作

 <?php
 include 'db.inc';
 session_start();
 $UserEmail =$_POST["EmailAddress"];
 $UserPassword =$_POST["Password"];
 $query = "SELECT * FROM members WHERE EmailAddress = '$UserEmail' 
         AND  password = '$UserPassword' "; 

$connection = mysql_connect($hostname, $username, $password) or die ("Unable to  connect!"); 
mysql_select_db($databaseName) or die ("Unable to select database!"); 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
    $_SESSION["authenticatedUser"] = $UserEmail;
      // Relocate to the logged-in page
     header("Location: Index.php");
  } 
  else 
   {

    $_SESSION["message"] = "Could not log in as $UserEmail " ;
     header("Location: Login.php");
    }    
 mysql_free_result($result); 
 mysql_close($connection); 

 ?>

And this is when the user is logged in. 这是用户登录时的时间。

<?php
session_start();
if (!isset($_SESSION["authenticatedUser"]))
{
  $_SESSION["message"] = "Please Login";
   header("Location: Login.php");
}
else
 { ?>

This is where the user email address is displayed 这是显示用户电子邮件地址的地方

<div class="Login">
<ul>
<?php if(isset($_SESSION['authenticatedUser']) && $_SESSION['authenticatedUser'] != null ) {?>
<li><a href="ProfilePage.php">Welcome <?php echo $_SESSION["authenticatedUser"] ?></a>    </li>
   <li><a href="logout.php"><span>Log Out</span></a></li>
<?php } else {?>
 <li><a href="login.php"><span>Log In</span></a></li>
 <?php } ?> 

Hope this is all relevant! 希望这一切有关!

I would recommend you read this manual page: 我建议您阅读此手册页:

http://de2.php.net/manual/en/session.examples.basic.php http://de2.php.net/manual/en/session.examples.basic.php

and this wiki page: 和这个维基页面:

http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Path http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Path

and the source of your problem should be clear. 问题的根源应该清楚。

A session is usually handled on the browser side by a cookie. 会话通常在Cookie的浏览器端进行处理。 A cookie has a domain: the site and path to which the cookie applies. Cookie具有一个域:Cookie适用的站点和路径。 Look at the cookies that are set in your browser; 查看浏览器中设置的cookie; your site's session cookie likely has a domain that applies to both of your web sites. 您网站的会话Cookie可能具有适用于您两个网站的域。

You'll need to make sure that the path on each site's session cookie is specific enough that the other site won't pick it up. 您需要确保每个站点的会话cookie上的路径都足够具体,以使另一个站点不会接听它。

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

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