我正在使用PHP和MySQL构建一个数据库驱动的网站。登录表单工作正常,但在我向代码添加新功能以使用户登录管理员或成员页面后,登录停止显示(例如)"欢迎,Pat,管理员"或者"欢迎,吉娜,会员"在表格上。
表单是一个小的表单,显示在网站的每个页面上,作为登录或提醒他们已经登录(使用会话)。现在,当我登录一个人时,它会将它们带到管理员或成员页面,但它不会在表单中显示登录信息,并且单击时退出按钮不会起作用。这是我的登录和注销代码,以及我用来访问管理页面或成员页面的函数的代码。
注销表格,应该在他们点击注销时显示为已登录,但它不起作用:
<form method="post" id="logoutform.inc.html">
<fieldset>
<legend>Logout</legend>
<?php
include('includes/functions.php');
if(isset($results)){
if ((isset($_SESSION['loginName'])) === $result['email'] && (isset($_SESSION['password'])) === $result['password']){
echo "Welcome, <br />";
echo "$level, <br />";
echo get_name($results);
// print_r($_POST);
print '<br />';
} else {
var_dump($results);
}
}
?>
<br /><br /><br />
<input type="submit" name="action" value="logout" />
</fieldset>
</form>
登录表格:
<form action="index.php" method="post" id="loginform.inc.html">
<fieldset>
<legend>Login</legend>
<label for="loginName" class="loginName">Username:</label>
<input id="loginName" name="loginName" type="text" value="<?php echo (isset($loginName['loginName'])); ?>" />
<label for="password" class="loginName">Password:</label>
<input id="password" name="password" type="password" value="<?php echo (isset($password['password'])); ?>" />
<input type="submit" name="submit" value="login" />
</fieldset>
</form>
退出功能:
function logout() {
$_SESSION = array();
session_destroy();
header('Location: home.php');
};
登录功能将您带到管理员或会员页面:这一个ISN&#39; T在其他地方打印任何内容:
function login($loginName, $password) {
$results = connect($loginName);
if ((isset($_SESSION['loginName'])) === $result['email'] && (isset($_SESSION['password'])) === $result['password']){
var_dump($loginName);
print "Welcome, $loginName";
} else {
echo "Sorry. You are not in our database";
}
if ( 'a' == $results['level'] ){
$level = "Administrator";
} elseif ( 'm' == $results['level'] ){
$level = "Member";
} else $level = '?';
if ($level === "Administrator"){
header('Location: /tires/admin/home.php');
exit();
} elseif ($level === "Member"){
header('Location: /tires/member/home.php');
exit();
}
include('includes/logoutform.inc.html');
}
这是CONNECT查询:
function connect($loginName){
global $db;
$query = "SELECT email, level, password FROM members WHERE email = '$loginName'";
$result = $db->query($query);
$results = $result->fetch(PDO::FETCH_ASSOC);
return $results;
};
答案 0 :(得分:0)
我在功能登录($ loginName,$ password)中做了一些更改请参考下面的代码,我查看它显示的代码 logoutform.inc.html 不包括在内。
function login($loginName, $password) {
$results = connect($loginName);
if ((isset($_SESSION['loginName'])) === $result['email'] && (isset($_SESSION ['password'])) === $result['password'])
{var_dump($loginName);
print "Welcome, $loginName";}
else {
echo "Sorry. You are not in our database";
}
include('includes/logoutform.inc.html');
if ( 'a' == $results['level'] ) {
header('Location: /tires/admin/home.php');
}
elseif ( 'm' == $results['level'] ) {
header('Location: /tires/member/home.php');
}
else $level = '?';
}