PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of xStream   JSCaptcha (unvulnerable anti-bot)   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: example+documentation
Class: JSCaptcha (unvulnerable anti-bot)
CAPTCHA validation using an image and JavaScript
Author: By
Last change:
Date: 17 years ago
Size: 3,090 bytes
 

Contents

Class file image Download
<?php
/*
Introduction:

This small library creates capthca image.
What is original?
It very easy for recognition... if you are a human! :)
There are no spam- or floodbot which can recognize it!
I hope this will be truth for long time

It consist of two parts: half of image drawn as usual whith PHP,
but it just a HALF(hehe, stupid bots can thing that this is original captcha),
second drawn with JavaScript (yes! it is possible!)
--------------------------------------------------------------

Using of class:
Step 1: creating captcha objects
JSCaptcha('div_name','session_name') - div_name is id property of HTML <div> tag in which captcha will be drawn
      | - session_name is the session name of captcha (see below)
      |
      |---- $captcha_object->captcha_js: is a JavaScript code, that you need run on your page, in example it placed in onLoad event
      |---- $captcha_object->session: stores the session name of captcha (see below), in example it uses GET method

Sometimes we need more than one captcha on page, so what we must do?
It's simple - we just create yet one (or more) JSCaptca objects
in $captcha->session you store name of session, so no problems with using multichaptcha

captcha value saved in $_SESSION['captcha']['session_name'] variable
after comparing you must clear it with unset();
WARNING! even if you have only one captcha you MUST set session, for exaple just use zero, i recommend use md5(microtime()) - it make you shure - image will be taken not from browser cache

Step 2: make valid HTML
a) you must include in <head> tag next lines:
        <script type="text/javascript" src="jg_c.js"></script> - grafical library
        <script type="text/javascript" src="base64.js"></script> - small crypto for JS
    without it nothing will happen
b) somwhere in your javascripts you must print (i do it whith PHP) javascript generated in object
c) then you must create DIV tag AND IMG tag in it whith SRC attribute targeting on pic.php?session=... (see sample below)

that's all
----------------------------------
Credits:
idea and realization - thanks to me ;)
JS library - credits goes to http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm (i think this is great innovation)

Yup! Sorry for my bad english.

All questions go here xbitstream@gmail.com
*/
include('captchagen.php');
$captcha=new JSCaptcha('C4PTCA_DIV',md5(microtime()));
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Captcha</title>
<!-- including JS library -->
<script type="text/javascript" src="jg_c.js"></script>
<script type="text/javascript" src="base64.js"></script>
</head>
<body style="margin:0; overflow:hidden;" onload="<? echo $captcha->captcha_js;?>">
<!-- creating div on vich we wil draw -->
<div id="C4PTCA_DIV" style="position:relative;top:0;left:0;width: 112;height: 48;">
<!-- call backend picture -->
<img src='pic.php?session=<?php echo $captcha->session;?>' style='width:112;height:48;'>
</div>
</body>
</html>