Login   Register  
PHP Classes

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2 years ago
Size: 2,198 bytes


Class file image Download
/* $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.
require_once( 'cCaptcha.php' );

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

if (isset(
$_POST['stat'])) {
   foreach (
$_POST as $n => $v)
"$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) {
"<font color='green'>Correct Captcha Code :)</font>";
   } else {
"<font color='red'>Invalid Captcha Code :(</font>";

<form action="example.php" method="post">
   <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"/>