logo
Blog single photo

Simple Captcha code


                        

 

Try out following this example


<!DOCTYPE html>  
<html >  
 <head>  
  <meta charset="UTF-8">  
  <title>Simple CAPTCHA</title>  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  <link rel="stylesheet" href="css/normalize.css">  
     <link rel="stylesheet" href="css/style.css">  
     <script src="js/jquery-3.0.0.min.js" type="text/javascript"></script>  
 </head>  
  <?php  
      function randomcap() {  
          $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'.md5(time());  
          $cpa = array();   
          $alphaLength = strlen($alphabet) - 1;   
          for ($i = 0; $i < 5; $i++) {  
          $n = rand(0, $alphaLength);  
          $cpa[] = $alphabet[$n];  
               }  
          return implode($cpa);   
          }  
                          ?>  
<?php   
if(isset($_POST['submit'])){  
     session_start();  
     $_SESSION['checkcode']=$_POST['caps'];  
     $Fcode=$_POST['cap'];  
     if($_SESSION['checkcode']===$Fcode){  
          //$field1=$_POST['field1'];  
          //$field2=$_POST['field2'];  
          //$fieldN=$_POST['fieldN'];  
          echo "<script type='text/javascript'> alert('submit Success');</script>";  
     }else{  
          echo "<script>$(document).ready(  
  function myFunction() {  
    $('#errorsw').text('Try again');  
  });</script>";  
     session_destroy();  
     }  
}  
?>       
<body>  
<div class="container">  
 <div class="row header">  
  <h1>Simple Captcha &nbsp;</h1>  
 </div>  
 <div class="row body">  
  <form method="post" action="" autocomplete="off">  
   <ul>  
          <li>  
     <div style="background-image: url('img/images.jpg'); width:200px; height:75px;">  
               <center><h2 id="cap1" style="font-family: 'Comic Sans MS', 'Comic Sans', cursive;color:#ffffff;"> </h2></center>  
               <input type="hidden" name="caps" id="caps" value="<?php echo randomcap(); ?>">  
               </div>  
               <script>  
               $(document).ready(  
                    function myFunction2() {  
                    $('#cap1').text($('#caps').val());  
                    });  
            </script>  
           <br>  
           <input type="text" name="cap" id="cap" value="">  
    </li>  
    <li>  
     <input class="btn btn-submit" name="submit" type="submit" id="submit" value="Submit" />  
     <small>or press <strong>enter</strong></small>  
           <div id="errorsw"></div>  
    </li>  
   </ul>  
  </form>   
 </div>  
</div>  
</body>  
</html>
Download Code - Simple Captcha
Top