自动访问被拒绝,发生了什么?

时间:2013-03-24 03:31:03

标签: php access-denied

好的,所以我刚刚解决了我的last question,我需要帮助了... 所以我修复了身份验证代码,但现在每次登录我的个人资料时,它都说我没有登录我的网站。这是access-denied.php代码:

<title>Access Denied</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Access Denied </h1>
<p align="center">&nbsp;</p>
<h4 align="center" class="err">Access Denied!<br />
  You do not have access to this resource.</h4>

这是我的auth.php代码:

//Start session
session_start();

//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['email']) || ($_SESSION['password'])){
    header("location: access-denied.php");
    exit();
}

这是我的个人资料页面代码:

<?php session_start(); ?>
<?php include("inc/incfiles/loggedheader.php")?>
<?php
    require_once('auth.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Index</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Welcome <? if(isset($_SESSION['SESS_fname'])){
    echo $_SESSION['SESS_fname'];
} ?></h1>
<a href="member-profile.php">My Profile</a> | <a href="logout.php">Logout</a>
<p>Welcome to your profile! </p>
</body>
</html>

为什么我无法登录我的个人资料?我对这种类型的PHP一无所知,我几乎还在学习,我的朋友(帮我构建我的网站)得到了代码,只是通过电子邮件发送给我。

2 个答案:

答案 0 :(得分:0)

行中存在问题

if(!isset($_SESSION['email']) || ($_SESSION['password'])){

你需要检查if条件的第二部分(密码检查)。在这里,您要检查会话中是否存在会话中存在电子邮件或密码的情况。所以即使电子邮件设置然后页面转到访问被拒绝由于第二个条件是真的。如有必要,您应该使用

if(!isset($_SESSION['email']) || !($_SESSION['password'])){

答案 1 :(得分:0)

问题在于:

if(!isset($_SESSION['email']) || !isset($_SESSION['password'])){
    ...
}