初学者问题。我需要为博客创建管理员登录,但我无法接受凭据。登录名是" user"密码是" pwed"仅用于测试目的。当我尝试登录时,即使他们不是,我的凭据也是无效的。如果成功,它只是转到管理页面。这应该是一个非常简单的错误,我正在查看,但我希望也许你们中的一个可以帮助我。
这是登录表单
<form id="form1" name="form1" method="post" action="">
<p>
<label for="name">Account Name:</label>
<input type="text" name="login" id="login" /><br/>
<label for="name">Password:</label>
<input type="text" name="password" id="name" />
</p>
<p>
<input type="submit" name="Submit1" value="Next >" />
</p>
</form>
&#13;
这是PHP
<?php
/* Check to see if there's a form submission */
if (array_key_exists('Submit1', $_POST)) { // each page needs a different name for the submit button
session_start();
// clear any existing session variables because this is the very first page of the survey
$_SESSION = array();
/* set required fields */
// must be an array, even if only one item is required
// if no fields are required, an empty array is needed. Otherwise, in_array() later in the script will generate an error
$required = array('name', 'password');
$_SESSION['missing'] = array();
// process the $_POST variables and save user input in the $_SESSION array
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $_SESSION['missing'] array
if (empty($temp) && in_array($key, $required)) {
array_push($_SESSION['missing'], $key);
}
// otherwise, assign to a variable of the same name as $key
else {
$_SESSION[$key] = $temp;
}
}
// if no required fields are missing, redirect to the next page
if (!$_SESSION['missing']) {
if ($_SESSION['name'] == "user" && $_SESSION['password'] == "pwed"){
// set a variable to control access to other pages, this variable will be checked on all other survey pages
$_SESSION['access'] = true;
header('Location: svar02.php');
exit;
}
else {
echo "We're sorry your login details seem to be incorrect";
}
}
else{
echo "It seems you've left a field blank";
}
//}
}
?>
答案 0 :(得分:1)
我认为问题出在以下位
$required = array('name', 'password');
这需要一个名为name
的字段,但您的表单已login
,请尝试:
$required = array('login', 'password');