开发者

basic question in php

When I try to log on it is not authenticating - I am not returning any errors. The user name and password is in the code (username and password is inside the php code not kept in a database).

This is my code:

<?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'); 
}
?>


Notice that

elseif($auth_status == 0); {
echo '<h4>Authentication error please try again! </h4>' . "\n\n";

is poorly formatted (and probably not what you want). What it does is execute ;(no-op, i.e. nothing) if $auth_status is zero. You probably meant to write:

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";
}


Your code have logic errors.

    <?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'); 

    ?>

Breaklines a lot are making it harder to see errors.


There were some weird brackets, can you test this?

    <?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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜