Left Quote    Every day I get up and look through the Forbes list of the richest people in America. If I
- Robert Orben    
Right Quote
[login] | [Register]


by: Free2Code


To gain use of this code sample, each step below must be followed:

  1. First, you need to copy the code sample provided and save it as a php file.
  2. Next, create a background and a cover image or image. The background can be some kind of simple texture, not too dark though. Cover image can be lines. Play around with it to get the effect you want. In the code sample, replace the links to the correct paths to the images you created.
  3. On the form you would like to protect from spam prevention, you need to insert the script as an image. That code woud look something like this:

    <img src="">

  4. Next, create an html text box (within a form) for the user to enter the CaSe sEnSiTiVe code that appears from the image/script. That code would look something like this:

    Enter Code: <input type="text" id="verify" name="verify" value="">

  5. Then in the validation part of your form, you need to ensure that the text box is not blank, and then if the values entered in the text box are equal to the code generated. The code generated will be stored in $_SESSION['code']; you can change that to whatever you want. Here is an example code to do that:

    if(!$_POST['verify']) {
        die('Verify field was blank.');
            } else {
    if($_SESSION['code'] != $_POST['verify']) {
        die('You did not enter the code from the box correctly.');

If you have covered all of the steps above, it should work fine for you. Play around with it and make it your own! Enjoy, -bs0d.

( );
$_SESSION['code'] = "";

//generate code
$string substrcryptrand( ) ), -);

//unwanted characters
$junk = array('.' ',' '/' '' '`' ';' '[' ,  ']' '-''_''*''&''^''%''$''#''@''!''~''+''('')''|''{''}''<''>''?'':''"''=');

//strip unwanted              
$string str_replace$junk''$string );

//image background
$im imagecreatefrompng"" );
$orange imagecolorallocate$imrand(1,100), rand(1,100), rand(1,100) );

$half imagesx$im ) / 2;
$start rand10$half 1.5 );
$y imagesy$im ) / 2;
$pos $start;

for ( 
$i 0$i strlen$string ); $i++ ) {
imagestring$im100$pos$y$string[$i], $orange );
$pos += rand(11,15);
$y += 5-rand(0,10);
//image cover
$cov imagecreatefrompng"" );
imagecopyresampled$im$cov0000300100300100 );

header('Content-type: image/png');

$_SESSION['code'] = $string;


No Comments for this page.

You Must be signed in or a member to comment.

Code Stats

Code Stats

2 Total Comments
3 Rating of 5 ( Votes)


Code Options

· Login to Rate This Code
· Login to Post a Comment
· Read more by this author
Digg This Code! Bookmark This Code Reddit: Bookmark This Code! BlinkList: Blink This Code! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Code Spurl: Mark This Code!

Code Samples


· Database Connection
· Users Online
· Pagination
· Comments Script
· IdealMySQL Class for PHP 5.0

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy