Forum Moderators: coopster

Message Too Old, No Replies

session problems and captcha

         

ayushchd

2:09 pm on Aug 5, 2007 (gmt 0)

10+ Year Member



<?
session_start();
/*register the session variable. */
session_register('new_string');

$im = ImageCreate(200, 25);

$white = ImageColorAllocate($im, 255, 126, 40);
$black = ImageColorAllocate($im, 212, 212, 212);

srand((double)microtime()*1000000);
/*Runs the string through the md5 function*/
$string = md5(rand(0,9999));
/*creates the new string. */

$new_string = substr($string, 17, 5);
/*fill image with black*/
include ('mysql.php');

if ($_SESSION['new_string']!= $random2) {
$notice = "<div id=\"failure\">Image Verification Failed.</div>";
echo "New String :". $_SESSION['new_string'];
echo "Input : $random2";

ImageFill($im, 0, 0, $black);
/*writes string */
ImageString($im, 10, 75, 5, $new_string, $white);

header('Content-type: image/png');
ImagePNG($im, "verify.png");
ImageDestroy($im);
?>

This script of mine works very well when i run it for the very first time,ie, when the session has no data in it. But once i submit the form, the data is assigned to session. And I want that data to change everytime, the user submits. Please Help.

jatar_k

6:35 pm on Aug 6, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use a timestamp and combine it with something else if you were worried, like username. If you had them in a db then you could just use the table's unique id

though I guess if you are using a timestamp it could just test that and if it is too old then show an expired message, no use storing them at all

as for expiration, you could have a cron clean up links, or have them in a db and scour them from there every so often

there are a ton of ways you could do it

This 31 message thread spans 2 pages: 31