Jump to content

[SOLVED] Random Number/Letter


JayLewis

Recommended Posts

I have a anti-scripting check on my site, it displays 2 random number or letters.

 

I want it to show just numbers. can anyone help?

 

<?
// *** CAPTCHA image generation ***
// *** http://frikk.tk ***

session_start();

// *** Tell the browser what kind of file is come'n at 'em! ***
header("Content-Type: image/jpeg");

// *** Send a generated image to the browser ***
create_image();
die();

// *** Function List ***
function create_image()
{
// *** Generate a passcode using md5
//	(it will be all lowercase hex letters and numbers ***
  
$md5 = md5(rand(0,9999));
$pass = substr($md5, 10, 2);

// *** Set the session cookie so we know what the passcode is ***
$_SESSION["pass"] = $pass;

// *** Create the image resource ***
$image = ImageCreatetruecolor(100, 20);  

// *** We are making two colors, white and black ***
$clr_white = ImageColorAllocate($image, 255, 255, 255);
$clr_black = ImageColorAllocate($image, 0, 0, 0);

// *** Make the background black ***
imagefill($image, 0, 0, $clr_black);

// *** Set the image height and width ***
imagefontheight(15);
imagefontwidth(15);

// *** Add the passcode in white to the image ***
imagestring($image, 5, 30, 3, $pass, $clr_white);

// *** Throw in some lines to trick those cheeky bots! ***
imageline($image, 5, 1, 50, 20, $clr_white);
imageline($image, 60, 1, 96, 20, $clr_white);

// *** Output the newly created image in jpeg format ***
imagejpeg($image);

// *** Clear up some memory... ***
imagedestroy($image);
}
?><p> </p>

Link to comment
Share on other sites

<?
session_start();

header("Content-Type: image/jpeg");

create_image();
die();

function create_image(){
$pass = rand(10,99);
$_SESSION["pass"] = $pass;
$image = ImageCreatetruecolor(100, 20);  
$clr_white = ImageColorAllocate($image, 255, 255, 255);
$clr_black = ImageColorAllocate($image, 0, 0, 0);
imagefill($image, 0, 0, $clr_black);
imagefontheight(15);
imagefontwidth(15);
imagestring($image, 5, 30, 3, $pass, $clr_white);
imageline($image, 5, 1, 50, 20, $clr_white);
imageline($image, 60, 1, 96, 20, $clr_white);
imagejpeg($image);
imagedestroy($image);
}
?><p> </p>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.