2011-02-05 6 views
0

로그온하려고하면 인증되지 않습니다. 오류가 반환되지 않습니다. 사용자 이름과 암호가 코드에 있습니다 (사용자 이름과 암호는 데이터베이스에 보관되지 않은 PHP 코드 안에 있습니다).PHP의 기본 질문

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

형식이 잘못되는 것을 (그리고 아마 당신이 원하지 않는 것을)

<?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 = '[email protected]'; 
    $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'); 
} 
?> 
+1

너무 길어 들여 쓰기가 너무 많습니다. 코드를 올바르게 포맷하십시오. 방금 질문에 대답하기 위해 엄청난 양의 공백을 스크롤하지 않으려 고합니다. – ThiefMaster

+0

어떻게 로그온 하시겠습니까? 이 코드에 제출하는 양식은 어디에 있습니까? 제출이라는 요소가 있습니까? 이 코드가 실행되면 $ _POST에 무엇이 있습니까? –

+1

죄송합니다. 먼저 기본 디버깅을 요청합니다. 테스트 출력을 한 라인 씩 차례대로 작성하여 정확한 문제를 찾아내는 방법으로 사용하면 안됩니다. * 그 질문은 가치가 있습니다. –

답변

1

주의 사항 :

이 내 코드입니다.이 0이면 ; (아무 작업도하지 않음)을 실행합니다. 다음과 같이 작성하려고했을 수 있습니다.

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

감사합니다 ... 또한 내 양식에 문제가있었습니다. 내 양식 이름은 "Email"과 "emailaddress"였습니다. 당신이 제공 한 것은 초기 호출 오류를 수정 한 후에 내가 가진 오류를 해결했습니다. –

+0

당신이 말할 수 있듯이 나는 PHP에 매우 익숙하다. –

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 = '[email protected]'; 
     $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'); 

    ?> 

많은 수의 오류로 인해 오류가 더 잘 보이지 않습니다.

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 = '[email protected]'; 
     $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'); 
    ?>