PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Archzilon Eshun-Davies   cCaptcha   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage of Captcha Class
Class: cCaptcha
Generate CAPTCHA images and validate its text
Author: By
Last change: Uses the new accessing methods
Date: 13 years ago
Size: 2,198 bytes
 

Contents

Class file image Download
<?php
/* $Id: example.php,v 0.1 2011/03/17 18:52:54 aedavies Exp $ */
/*
 * Copyright (c) 2009,2010,2011 Archzilon Eshun-Davies <laudarch@qremiaevolution.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
 
require_once( 'cCaptcha.php' );

 if (isset(
$_GET['captcha'])) {
   
$lch = new cCaptcha('font.ttf');
   
header("Content-Type: image/png"); # must always be done
   
$lch->showcaptcha(20);
    unset(
$lch );
 }

if (isset(
$_POST['stat'])) {
   foreach (
$_POST as $n => $v)
       echo
"$n => $v<br />";

  
# Checking if the captcha given by user is correct
   # Remember to session_start() or $sess = new cSession;
  
$ret = cCaptcha::chkcaptchacode($_POST['sec_code']);
   if (
$ret) {
      echo
"<font color='green'>Correct Captcha Code :)</font>";
   } else {
      echo
"<font color='red'>Invalid Captcha Code :(</font>";
   }
}
?>

<form action="example.php" method="post">
   <fieldset>
   <legend>Log in</legend>
   Username:<br /><input type="text" name="uname" /><br />
   Password:<br /><input type="password" name="passwd" /><br />
   Enter the characters below(Case Sensitive Text):<br /><input class="text" type='text' name='sec_code' /><br />
   <img src="?captcha" name="sec_code" id="sec_code" title="[Captcha Code - Case sensitive]" /><br />
   <a href="javascript:;" onclick="document.getElementById('sec_code').src = '?captcha='+Math.random();">Reload Captcha</a>
   <input type='hidden' name="stat" value="ready" />
   <br /><input type="submit" value="Log in"/>
   </fieldset>
</form>