Jump to content

Image verification


ted_chou12

Recommended Posts

Hello, I don't understand why this code doesnt work:

<?php session_start();
//send img to header as jpg file
header('Content-type: image/jpeg');

//generate random string:
$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$string = substr(str_shuffle($alphanum), 0, 5);

//store in session (md5)
$_SESSION['imgverify'] = md5($string);

//create image from existing bgs
$bgno = rand(1, 4);
$image = imagecreatefromjpeg("images/background$bgno.jpg");

//white bg, black text
$bgcolor = imagecolorallocate($image, 255, 255, 255);
$textcolor = imagecolorallocate($image, 0, 0, 0);

//producing image (img, font, x, y, text, color)
imagestring($image, 5, 7, 8, $string, $textcolor);

imagejpeg($image);
imagedestroy($image);?>

and

<?php session_start();
//image verification passed?
if ($_SESSION['imgverify'] != md5($imgverify))
{echo $imgverify_failed; $invalid = true;}?>
<label>Image Verification</label>
<img id="image" src="imgverify.php" onclick="reloadImg();" />

But the $_SESSION['imgverify'] is not md5 encoded in the second page, I have no idea what's wrong, ???

Thanks,

Ted

Link to comment
https://forums.phpfreaks.com/topic/148719-image-verification/
Share on other sites

I found where the problem is, but i still have no clue why it is:

//on the second page, where the submission of image verify code is:
if (isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$tname = $_POST['tname'];
$temail = $_POST['temail'];
$message = $_POST['message'];
$imgverify = $_POST['imgverify'];//after here the $_SESSION['imgverify'] suddenly turns to non md5 coded, but before this line $_SESSION['imgverify'] is fine.

I think this is a bug that ive found, i spent hours trying to look for this error, is so annoying... :(

Link to comment
https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-784908
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.