Jump to content


Photo

random numbers


  • Please log in to reply
3 replies to this topic

#1 acidglitter

acidglitter
  • Members
  • PipPipPip
  • Advanced Member
  • 355 posts

Posted 14 April 2006 - 10:08 PM

i have a form at my website and i don't want it to get abused by spam. i was thinking maybe i should have a verification thing where you have to enter the 5 or 6 random numbers that show up. how could i do that?
my makeup site <3
http://vanillaeyeliner.com

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 April 2006 - 10:17 PM

Search for captcha to find something you like. I have a downloadable script set at [a href=\"http://www.digitalmidget.com/php_noob/captcha.php\" target=\"_blank\"]http://www.digitalmidget.com/php_noob/captcha.php[/a] that might be useful.
Legend has it that reading the manual never killed anyone.
My site

#3 underparnv

underparnv
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationReno, Nevada

Posted 14 April 2006 - 10:35 PM

Since I'm in a good mood...and it's Friday! :)

image.php
<?php
session_start();

// make a string with all the characters that we
// want to use as the verification code
$alphanum  = "ABCDEFGHJKLMNPQRTWXYZ2345689";

// generate the verication code
// change the last digit in this function for the length of string you would like
$rand = substr(str_shuffle($alphanum), 0, 4);

// create an image object using the chosen background
// email me at underparnv@gmail.com for this background image
$image = imagecreatefrompng("background3.png");

$textColor = imagecolorallocate ($image, 0, 0, 0);

// write the code on the background image
imagestring ($image, 5, 5, 8,  $rand, $textColor);


// create the hash for the verification code
// and put it in the session
$_SESSION['image_random_value'] = md5($rand);

// send several headers to make sure the image is not cached
// taken directly from the PHP Manual

// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");


// send the content type header so the image is displayed properly
header('Content-type: image/jpeg');

// send the image to the browser
imagejpeg($image);

// destroy the image to free up the memory
imagedestroy($image);
?>

register.php (or whatever the name of your page with the registration form on it would be)
<?php
session_start();
echo "<form action=\"form_handler.php\" method=\"post\">
<b>Human Verification:</b><br />
Input the text you see in this image.  <b>This is case sensitive</b>!<br />
<img src=\"image.php\" alt=\"Verification Image\" title=\"Verification Image\" /><br />
<input type=\"text\" name=\"human\" size=\"5\" /><br /><br />

<h2>Submit Form</h2>
<hr><br />
<input type=\"submit\" value=\"Submit\" />

</form>";
?>

form_handler.php
<?php
$human = $_POST["human"];
if (md5($human) != $_SESSION["image_random_value"]) {
     echo "Invalid human verification image entry!";
} else {
     echo "Validation passes";
}
?>

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."

The Sporting Edge - Free NFL Football Pool


#4 acidglitter

acidglitter
  • Members
  • PipPipPip
  • Advanced Member
  • 355 posts

Posted 03 June 2006 - 06:43 PM

thats awesome. thanks! :)

i shortened it all to one page and it works, but im wondering if spammers could get through it because of how i changed it? and where should the $rand be md5'd? on page 1 or 2?

<?php
if(!$_GET['p']==2){

$alphanum="ABCDEFGHJKLMNPQRTWXYZ2345689";
$rand=substr(str_shuffle($alphanum), 0, 4);
$random=md5($rand);

echo "<form action=\"kk.php?p=2\" method=\"post\">
$rand<br />
<input type=\"text\" name=\"human\" size=\"5\" />
<input type=\"hidden\" name=\"random\" value=\"$random\">
<input type=\"submit\" value=\"Submit\" /></form>";

} else {

$random=$_POST['random'];
$human = $_POST["human"];
if (md5($human) != $random) {
     echo "Invalid human verification image entry!";
} else {
     echo "Validation passes";
}
} ?>

my makeup site <3
http://vanillaeyeliner.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users