首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php中的基本问题

php中的基本问题
EN

Stack Overflow用户
提问于 2011-02-05 22:36:15
回答 3查看 139关注 0票数 0

当我尝试登录时,它不是身份验证-我没有返回任何错误。用户名和密码在代码中(用户名和密码在php代码中,而不是保存在数据库中)。

这是我的代码:

代码语言:javascript
复制
<?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'); 
}
?>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-02-05 22:51:58

请注意,

代码语言:javascript
复制
elseif($auth_status == 0); {
echo '<h4>Authentication error please try again! </h4>' . "\n\n";

格式不佳(可能不是您想要的)。如果$auth_status为零,它所做的就是执行;(no-op,即不执行任何操作)。你可能想写下:

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2011-02-05 22:55:53

您的代码存在逻辑错误。

代码语言:javascript
复制
    <?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'); 

    ?>

过多的分隔线使得看错变得更加困难。

票数 1
EN

Stack Overflow用户

发布于 2011-02-05 22:56:52

有一些奇怪的支架,你能测试一下吗?

代码语言:javascript
复制
    <?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'); 
    ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4907409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档