Login   Register  
PHP Classes
elePHPant
Icontem

File: ca_demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Liq  >  caText n caMath  >  ca_demo.php  >  Download  
File: ca_demo.php
Role: Example script
Content type: text/plain
Description: source example
Class: caText n caMath
CAPTCHA validation with text and math operations
Author: By
Last change:
Date: 2007-08-21 06:25
Size: 1,994 bytes
 

Contents

Class file image Download
<?php

    
include('catext.class.php');
    include(
'camath.class.php');

    
/***** FORM HANDLE *****/    
    
echo "<h2><font color=\"red\">";
    if(isset(
$_POST[submit_ctext])){
        if(
md5(trim($_POST[code])) == trim($_POST[code_ori]))
            echo 
"Code accepted..";
        else 
            echo 
"Code False!!!";        
    }

    if(isset(
$_POST[submit_cmath])){
        
// use proper encryption function
        
if(md5(trim($_POST[code])) == trim($_POST[code_ori]))
            echo 
"Code accepted..";
        else 
            echo 
"Code False!!!";
        
    }
    echo 
"</font></h2>";
    
/***** END FORM HANDLE *****/    

    // create
    
$cText = new catext;
    
$cMath= new camath;

?>

        
    <h3>Example for caText and caMath class with md5 encryption..</h3>
    <p>This class used for preventing robot or non human to posting via form.
    I don't like use captcha because i usually disabled displaying image on my browser setting.
    So I build this class :).</p>
    
    <p>For general purpose, this class can protect your web form. 
    But, i think this class is easier to break than real captcha.. so used it at your own risk.</p>
    
    
    <br><br>
    <b># <u> caText example:</u></b>
    <br /><br />

    <form method=post action="">
    <input type="text" name="name"> Name<br>
    <textarea name="comment" rows="5" cols="30">your comment here..</textarea>
    <br>
    <?php $cText->generate(); ?> <input type="text" name="code" size="5">
    <input type="hidden" name="code_ori" value="<? echo md5($cText->get_key());?>">
    <br>
    <input type="submit" name="submit_ctext">
    </form>
    
    <br>
    <b># <u>caMath example:</u></b>
    <br /><br />
    
    <form method=post action="">
    <input type="text" name="name"> Name<br>
    <textarea name="comment" rows="5" cols="30">your comment here..</textarea>
    <br>
    <?php $key_ori $cMath->generate('md5'); ?> <input type="text" name="code" size="5">
    <input type="hidden" name="code_ori" value="<? echo $key_ori;?>">
    <br>
    <input type="submit" name="submit_cmath">
    </form> 

    <br>
    &copy; deepforest [colique at gmail.com]