2012-02-11 63 views
0

我想創建一個登錄名和我有一些問題。當我登錄我的代碼時會提示我進行身份驗證(因爲它應該如果我輸入了錯誤的密碼),但是現在我已將密碼硬編碼。即使當我輸入正確的密碼時,也沒有打開鏈接,所以我可以訪問該頁面。PHP登錄表單發出

注意下面我的代碼:

網站配置文件

<?php 
    define('WEB_ROOT' , '/mjcrawle/bank/'); 
    define('ABSOLUTE_PATH' , '/home/mjcrawle/main/bank/'); 
    define('URL_ROOT' , 'http://tomcat.cit.iupui.edu/mjcrawle/main/'); 
    define('APP_ROOT' , 'http://tomcat.cit.iupui.edu/mjcrawle/main/bank/'); 
?> 

登錄進程文件

 <?php 

      /*Required Fields*/ 
      require_once('websiteconfig.inc.php'); 

      /*FUNCTIONS*/ 

      /*VERRIFY EMAIL ADDRESS AND PASSWORD AND MATCH IN SYSTEM*/ 
      function validateLogin($emailaddress='', $password=''){ 

      /*INITIALIZES VARIABLES*/ 
      $email_key = '[email protected]'; 
      $password_key = '1234'; 

      $auth_match = 0; 

      /* CHECK FOR MATCH */ 
      if($emailaddress == $email_key && $password == $password_key){ 
       $auth_match = 1; 
       } 
      return $auth_match; 
      } 

      /*CLEAN FORM DATA*/ 
      function sanitize($form_var) { 
       $clean_data = strtolower(trim($form_var)); 

       return $clean_data; 
      } 

      /*PAGE VARIABLES*/ 
      $auth_status = 0; 

      /*DETERMINE FORM HAS BEEN SUBMITTED*/ 
      if(array_key_exists('submit', $_POST)) { 

      /*SANITIZE FORM DATA*/ 
      $emailaddress = sanitize($_POST['emailaddress']); 
      $password = sanitize($_POST['password']); 

      /*VALIDATE FORM DATA*/ 
      $auth_status = validateLogin($emailaddress, $password); 

      } 


     ?> 



    </div><div class="container" id="shadow"> 
    <div> 
     <?php 

      include(ABSOLUTE_PATH . 'header.inc.php'); 

      if($auth_status == 1){ 
       /*AUTHENTICATION SUCCESS*/ 
       echo '<h4>Welcome Back, Betty!</4>' . "\n\n"; 
       echo '<ul>' . "\n"; 
       echo "\t" . '<li><a href="' . APP_ROOT . 'onlinebanking" title="Online Banking">Online Banking</a></li>' . "\n\n"; 
       echo '</ul>'; 


      } elseif($auth_status == 0){ 
       /*AUTHENTICATION FAILED*/ 
       echo '<h4 class="error">Authentication Error!</h4>' . "\n\n"; 
       echo '<p>Incorrect e-mail address and/or password submitted. Please try again.</p>'; 
      } 

     ?> 


      <div> 





      </div><!--End of main content--> 
     <?php 
      include(ABSOLUTE_PATH . 'footer.inc.php'); 
     ?> 

這是我的登錄表單

<div id="login_form"> 
    <form id="login" method="post" action="processlogin.php"> 
    <label for="emailaddress"> E-mail Address: </label> 
    <input type="text" id="emailaddress" name"emailaddress" maxlength="100" tabindex="1" /> 

    <label for="password"> Password: </label> 
    <input type="password" id="password" name="password" maxlength="13" tabindex="2" /> 

    <input type="submit" id="login_submit" name="submit" value="login"/> 

    </form> 
</div> 

這是我的主索引頁:

<?php 
     require_once('websiteconfig.inc.php'); 
    ?> 

<div> 
<h1 class="h1" align="center"> 
1%'er Savings <bold> & </bold> Loan </h1> 
</h1> 
</hr> 

</div><!--End of Body-->  <?php   require_once('footer.inc.php');   ?> </div><!--end of header--> 

這是我的頭

首頁登錄頁/ _assets /樣式/風格.css「/>

/_assets/images/bkrnd_top.png 「> /_assets/images/bkgrnd_tl.png」 WIDTH = 「205」 高度= 「61」> /_assets/images/logo.png 「WIDTH = 」160「 高度= 」61「>

/_assets/images/background_headerarea.png」>
   首頁    |     TBA     |     TBA     |     TBA     |     TBA     |     TBA

回答

2

你在你的代碼中的錯誤。你的登錄表單缺少=

<input type="text" id="emailaddress" name="emailaddress" maxlength="100" tabindex="1" /> 

你有name"emailaddress"

+0

哇....我一直打算在我的代碼小時....謝謝! – 2012-02-11 20:21:37

+1

重要提示 - 如果某些內容不能按預期工作,請使用'print_r($ _ POST)將您發佈的內容轉儲到屏幕上;' - 然後您就可以準確瞭解從表單中收到的數據 – MrJ 2012-02-11 21:03:50