|
-
Nov 28th, 2009, 10:07 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] anti-spam image or image validator whatever...
anyone got a working script for this? i can't seem to get anything working that i find when i search...
edit: i found a code to generate an image, and i use rand to generate text on it...
now when i press a submit button, how can i check if the generated text matches the textbox?
Code:
<?php
$my_img = imagecreate( 60, 20 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
$rand_string = rand(999999, 9999999);
imagestring( $my_img, 4, 1, 2, $rand_string,
$text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, 0);
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>
Last edited by Justa Lol; Nov 28th, 2009 at 10:19 AM.
-
Nov 28th, 2009, 10:42 AM
#2
Thread Starter
Fanatic Member
Re: anti-spam image or image validator whatever...
i belive i got 1 step further but 1 problem more...
Code:
<?php
//image.php
session_start();
$_SESSION['rand_string'] = $random;
$my_img = imagecreate( 60, 20 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
$rand_string = rand(999999, 9999999);
$random = $rand_string;
imagestring( $my_img, 4, 1, 2, $random,
$text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, 0);
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>
Code:
<?php
//index.php or whatever
session_start();
echo $_SESSION['rand_string']; //retrieve data
?>
<img src="image.php" width="60px" height="20px">
everything seems to work except that the random value isn't the same...
Last edited by Justa Lol; Nov 28th, 2009 at 10:48 AM.
-
Nov 28th, 2009, 11:01 AM
#3
Re: anti-spam image or image validator whatever...
you're echoing out rand_string before it's set by image.php. of course it wouldn't be the same. you have to set it by calling image.php, and then echo it.
-
Nov 28th, 2009, 11:14 AM
#4
Thread Starter
Fanatic Member
Re: anti-spam image or image validator whatever...
can you show some code, because i'm totally blank now..
edit: never mind i got it now. thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|