2014-06-08 3 views
-1

사용자가 올바른 captcha 코드를 입력 한 다음 사용자 데이터가 데이터베이스에 저장되면 captcha 코드가 잘못되면 출력을 잘못된 것으로 인쇄하는 등록 양식을 만들고 있습니다. 하지만 내 문제는 사용자가 잘못된 captcha의 코드를 입력하면 데이터베이스에 사용자의 데이터를 저장할뿐만 아니라 "잘못된 코드"출력을 표시하는 것입니다. pls가 내가 잘못한 곳에서 도움을 줍니까?내 captcha가 내 등록 양식에 작동하지 않습니다

여기 내 코드입니다.

<?php session_start(); ?> 
<?php 
// show potential errors/feedback (from registration object) 
if (isset($registration)) { 
    if ($registration->errors) { 
     foreach ($registration->errors as $error) { 
      echo '<div class="alert-box error"><span>Error: </span>'.$error.'</div>'; 
     } 
    } 
    if ($registration->messages) { 
     foreach ($registration->messages as $message) { 
      echo '<div class="alert-box success"><span>Success: </span>'.$message.'</div>'; 
     } 
    } 
} 

/** Validate captcha */ 
if (!empty($_REQUEST['captcha'])) { 
    if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) { 
     $captcha_message ="Invalid captcha"; 
     $style = "background-color: #FF606C color:#555 
     border-radius: 0px 
     font-family:Tahoma,Geneva,Arial,sans-serif font-size:11px; 
     font-size: 18px 
     padding: 30px 36px 
     margin:10px font-weight:bold 
     text-transform:uppercase border:2px solid #0c0b0b 
     background-color: #ff7e48 "; 

     echo' 
     <div id="result" style="$style"> 
     <h2><div class="alert-box error"><span>error: </span>'.$captcha_message.'</div></h2> 
     </div>'; 

    } else { 
     $captcha_message = "Valid captcha"; 
     $style = "background-color: #CCFF99"; 
    } 


    $request_captcha = htmlspecialchars($_REQUEST['captcha']); 
    unset($_SESSION['captcha']); 
} 
?> 

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Registration with Linkvessel and collaborate with college's friends</title> 
     <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
     <script> 
      $(function(){ 
       $("#datepicker").datepicker(); 
      });    
     </script> 
     <style> 
      .alert-box { 
     color:#555; 
     border-radius: 0px; 
     font-family:Tahoma,Geneva,Arial,sans-serif; font-size:11px; font-size: 18px; 
     padding: 30px 36px; 
     margin:10px; 
      } 
      .alert-box span { 
     font-weight:bold; 
     text-transform:uppercase; 
      } 
      .error { 
     border:2px solid #0c0b0b; 
       background-color: #ff7e48; 
      } 

      .success{ 
      border:2px solid #0c0b0b; 
      background-color: #a3ea42; 
      } 
     </style> 
    </head> 
    <body onload="document.getElementById('captcha-form').focus()"> 
     <div id="header"> 
      <img id="logo_size" src="./images/logo.png" onmousedown="return false"> 
     </div><br><br><br> 

     <form id="form_box" method="post" action="register.php" name="registerform"> 
       <div id="title"> 
        <h2>REGISTRATION FORM</h2> 
       </div> 

       <div class="controls pos_selectbox"> 
        <select id="basic" name="user_college" class="input-medium"> 
         <option>Select College</option> 
         <option>MAIIT kota</option> 
        </select>&nbsp; &nbsp; 

        <select id="basic" name="user_branch" class="input-medium"> 
         <option>Select Branch</option> 
         <option>Computer science</option> 
         <option>Civil</option> 
         <option>Mechanical</option> 
         <option>Electrical</option> 
         <option>Bioinformatic</option> 
        </select>&nbsp; &nbsp; 

        <select id="basic" name="user_year" class="input-medium"> 
         <option>Select year</option> 
         <option>1st year</option> 
         <option>2nd year</option> 
         <option>3rd year</option> 
         <option>4th year</option> 
         <option>Year completed</option> 
        </select>&nbsp; &nbsp; 
       </div><br> 

       <input id="input_pos" type="email" name="user_email" required="" placeholder="Email address" /><br><br> 

       <input id="input_pos" type="password" name="user_password_new" required="" placeholder="Password" /><br><br> 

       <input id="input_pos" type="password" name="user_password_repeat" required="" placeholder="Confirm password" /><br><br> 

       <input id="name_pos" type="text" name="user_firstname" required="" placeholder="First name" />&nbsp; 

       <input id="name_pos2" type="text" name="user_lastname" required="" placeholder="Last name" /><br><br> 

       <input id="datepicker" type="text" name="user_dob" required="" placeholder="Date of birth" /><br><br> 

       <input id="name_pos" type="text" name="user_state" required="" placeholder="State" />&nbsp; 

       <input id="name_pos2" type="text" name="user_city" required="" placeholder="city" />&nbsp;<br><br> 

       <img src="captcha.php" id="captcha" /><br/> 

       <a href="#" onclick=" 
    document.getElementById('captcha').src='captcha.php?'+Math.random(); 
    document.getElementById('captcha-form').focus();" 
    id="change-image">Not readable? Change text.</a><br/><br/> 

    <input type="text" name="captcha" id="captcha-form" autocomplete="off" placeholder="Type code here" /><br><br> 

       <input type="submit" name="register" id="pos_submit" class="btn btn-primary btn-large" value="Create account.."/> 
      </form> 
</html> 

<?php 
    // checking for minimum PHP version 
    if (version_compare(PHP_VERSION, '5.3.7', '<')) { 
     exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !"); 
    } else if (version_compare(PHP_VERSION, '5.5.0', '<')) { 
     // if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php 
     // (this library adds the PHP 5.5 password hashing functions to older versions of PHP) 
     require_once("libraries/password_compatibility_library.php"); 
    } 

    // include the configs/constants for the database connection 
    require_once("config/db.php"); 

    // load the registration class 
    require_once("classes/Registration.php"); 

    // create the registration object. when this object is created, it will do all registration stuff automatically 
    // so this single line handles the entire registration process. 
    $registration = new Registration(); 

    // show the register view (with the registration form, and messages/errors) 
    include("views/register.php"); 

?> 
+0

<form id="form_box" method="post" action="register.php" name="registerform"> 

교체, 날이 파일을 보일 수 있는가? 나는 당신이 register.php를 호출 할 때 데이터베이스에 관한 정보를 추가한다고 생각한다. – Kate

+0

내 편집을 참조 ... – user3719524

+0

@Kate 나는 나의 코드를 편집했다 ... – user3719524

답변

0

간단한 예를 편집 register.php 제거하고 보안 문자가 올 경우 그렇지에 데이터베이스에 정보를 추가합니다.

/** Validate captcha */ 
if (!empty($_REQUEST['captcha'])) { 
    if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) { 
     $captcha_message ="Invalid captcha"; 
     $style = "background-color: #FF606C color:#555 
     border-radius: 0px 
     font-family:Tahoma,Geneva,Arial,sans-serif font-size:11px; 
     font-size: 18px 
     padding: 30px 36px 
     margin:10px font-weight:bold 
     text-transform:uppercase border:2px solid #0c0b0b 
     background-color: #ff7e48 "; 

     echo' 
     <div id="result" style="$style"> 
     <h2><div class="alert-box error"><span>error: </span>'.$captcha_message.'</div></h2> 
     </div>'; 

    } else { 
     $captcha_message = "Valid captcha"; 
     $style = "background-color: #CCFF99"; 
     //insert in database here and redirect to index or profil 
    } 
    $request_captcha = htmlspecialchars($_REQUEST['captcha']); 
    unset($_SESSION['captcha']); 
} 

하고 register.php를 호출

<form id="form_box" method="post" action="" name="registerform"> 
+0

당신은'header ('Location : -');'를 사용하여 register.php를 리디렉션해야 함을 의미합니다. – user3719524

관련 문제