当我尝试登录时,它没有进行身份验证 - 我没有返回任何错误。用户名和密码在代码中(用户名和密码在PHP代码中未保存在数据库中)。
这是我的代码:
<?php
/* This is the location of the file and will be used as the baseline for all
of my files writing of code within php. */
/*require files for application */
require_once('websiteconfig.inc.php');
define( 'ABSOLUTE_PATH ', '../public_html/cit0215/assignment2/' );
/*This will define my index.php file */
define('URL_ROOT ', 'https://wiki.cit.iupui.edu/~mjcrawle/cit0215/assignment2/index.php/');
/*functions that validate logins */
function validateLogin($emailaddress='', $password='') {
/*Initialized the Variable from the original from the form */
$email_key = 'betty@abc.com';
$password_key = '1234';
$auth_match = 0;
/*This is the first If statement the test username and password*/
if ($emailaddress == $email_key && $password == $password_key) {
$auth_match=1;
}
/*this is what ensure the username and password are correct*/
return $auth_match;
}
function sanitize($form_var){
$clean_data = strtolower(trim($form_var));
return $clean_data;
}
/*Authticate the status of logins*/
$auth_status =0;
/*Determine if the form data was submitted*/
if (array_key_exists('submit', $_POST)){
/*this removes left over data*/
$emailaddress = sanitize($_POST['emailaddress']);
$password = sanitize($_POST['password']);
/*verify form data*/
$auth_status = validateLogin($emailaddress, $password);
}
include('header/header.inc.php');{
if($auth_status == 1){
/*successful logon*/
echo '<h3>Welcome Back, Betty!... Your not ugly after all</h3>' . "\n\n";
echo '<ul>' . "\n";
echo "\t" . '<li><a href"' . URL_ROOT . 'onlinebanking" title="Online
Banking">On Line Banking</a> </li>' . "\n\n";
echo '</u>';
}
elseif($auth_status == 0); {
/*authentication has failed*/
echo '<h4>Authentication error please try again! </h4>' . "\n\n";
echo '<p> Please make sure that the "Numbers lock" or "Caps Lock" is not
on and re-type your password.</p>';
}
include('footer_nav/footer.inc.php');
}
?>
答案 0 :(得分:1)
请注意
elseif($auth_status == 0); {
echo '<h4>Authentication error please try again! </h4>' . "\n\n";
格式不正确(可能不是你想要的)。如果;
为零,它的作用是执行$auth_status
(无操作,即无)。你可能想写:
if ($auth_status) {
echo '<h3>Welcome Back, Betty!</h3>';
} else { // or elseif (!$auth_status) { // <-- no semi-colon
echo '<h4>Authentication error please try again! </h4>' . "\n\n";
}
答案 1 :(得分:1)
您的代码存在逻辑错误。
<?php
/* This is the locaiton of the file and will be */
/*used as the baseline for all of my files writing */
/*of code within php. */
/*require files for application */
require_once('websiteconfig.inc.php');
define( 'ABSOLUTE_PATH ', '../public_html/cit0215/assignment2/' );
/*This will define my index.php file */
define( 'URL_ROOT ', 'https://wiki.cit.iupui.edu/~mjcrawle/cit0215/assignment2/index.php/');
/*functions that validate logins */
function validateLogin($emailaddress='', $password='') {
/*Initialized the Variable from the original from the form */
$email_key = 'betty@abc.com';
$password_key = '1234';
$auth_match =0;
/*This is the first If statement the test username and password*/
if($emailaddress == $email_key && $password == $password_key) {
$auth_match=1;
}
/*this is what ensure the username and password are correct*/
return $auth_match;
}
function sanitize($form_var){
$clean_data = strtolower(trim($form_var));
return $clean_data;
}
/*Authticate the status of logins*/
$auth_status =0;
/*Determine if the form data was submitted*/
if (array_key_exists('submit', $_POST)){
/*this removes left over data*/
$emailaddress = sanitize($_POST['emailaddress']);
$password = sanitize($_POST['password']);
/*verify form data*/
$auth_status = validateLogin($emailaddress, $password);
}
include('header/header.inc.php');
if($auth_status == 1){
/*successful logon*/
echo '<h3>Welcome Back, Betty!... Your not ugly after all</h3>' . "\n\n";
echo '<ul>' . "\n";
echo "\t" . '<li><a href"' . URL_ROOT . 'onlinebanking" title="Online Banking">On Line Banking</a> </li>' . "\n\n";
echo '</u>';
// FIXME - ";" do not operation here. Your test for $auth_status do nothing.
} elseif($auth_status == 0); {
/*authentication has failed*/
echo '<h4>Authentication error please try again! </h4>' . "\n\n";
echo '<p> Please make sure that the "Numbers lock" or "Caps Lock" is not on and re-type your password.</p>';
}
include('footer_nav/footer.inc.php');
?>
分裂很多,使得查看错误变得更加困难。
答案 2 :(得分:0)
有一些奇怪的括号,你可以测试一下吗?
<?php
/* This is the location of the file and will be used as the baseline for all
of my files writing of code within php. */
/*require files for application */
require_once('websiteconfig.inc.php');
define( 'ABSOLUTE_PATH ', '../public_html/cit0215/assignment2/' );
/*This will define my index.php file */
define('URL_ROOT ', 'https://wiki.cit.iupui.edu/~mjcrawle/cit0215/assignment2/index.php/');
/*functions that validate logins */
function validateLogin($emailaddress='', $password='') {
/*Initialized the Variable from the original from the form */
$email_key = 'betty@abc.com';
$password_key = '1234';
$auth_match = 0;
/*This is the first If statement the test username and password*/
if ($emailaddress == $email_key && $password == $password_key) {
/*this is what ensure the username and password are correct*/
return 1;
}
return false;
}
function sanitize($form_var){
$clean_data = strtolower(trim($form_var));
return $clean_data;
}
/*Authticate the status of logins*/
$auth_status =0;
/*Determine if the form data was submitted*/
if (array_key_exists('submit', $_POST)){
/*this removes left over data*/
$emailaddress = sanitize($_POST['emailaddress']);
$password = sanitize($_POST['password']);
/*verify form data*/
if ( validateLogin($emailaddress, $password) ){
$auth_status = 1;
}
}
include('header/header.inc.php');
if($auth_status == 1){
/*successful logon*/
echo '<h3>Welcome Back, Betty!... Your not ugly after all</h3>' . "\n\n";
echo '<ul>' . "\n";
echo "\t" . '<li><a href"' . URL_ROOT . 'onlinebanking" title="Online Banking">On Line Banking</a> </li>' . "\n\n";
echo '</u>';
}
else{
/*authentication has failed*/
echo '<h4>Authentication error please try again! </h4>' . "\n\n";
echo '<p> Please make sure that the "Numbers lock" or "Caps Lock" is not on and re-type your password.</p>';
}
include('footer_nav/footer.inc.php');
?>