Jump to content

Help Me With This Simple CAPTCHA Script.


Vermillion

Recommended Posts

I have been coding my site for months now, and weeks on just the registration script. Today, I had planned to finally finish my registration script, but I noticed that there's a problem with my captcha scripts thanks to the fact that my Ajax wouldn't deliver the correct Captcha.

 

So trying to hunt the bug down, I started to make the script, and surprisingly, I found the bug very quickly, but unfortunately I still can't find a solution for it.

 

This is the script that outputs the Captcha image:

 

<?php

session_start();

// Everything related to the Captcha.

$captchamd5 = md5(microtime() * mktime());

$string = substr($captchamd5, 0, 7); //The Captcha string will only have 7 characters.

$captcha = imagecreatefrompng("../graphics/captcha_bg.png");

$white = imagecolorallocate($captcha, 255, 255, 255);
$line = imagecolorallocate($captcha, 233, 239, 239);

imageline($captcha, 0, 0, 39, 29, $line);
imageline($captcha, 40, 0, 64, 29, $line);

imagestring($captcha, 5, 20, 10, $string, $white);

$_SESSION['captcha'] = $string;

header("Content-type: image/png");
imagepng($captcha);

?>

 

And the test page I made to test it just has this code:

 

<?php 
  session_start();

?> 

<?php
echo '<img src="AwingsCLF/register/captcha.php"/>';
echo $_SESSION['captcha'];

?>

 

Like you can see, the first script assigns the value to my $_SESSION['captcha'] array value, and the second script echoes that output, but first including the captcha as an image. The problem is that the values on the Captcha are different; what I echo is different than what I see in the image, like you can see on the pic below:

 

30d86ww.jpg

 

Any help with this will be really appreciated. I don't want to change the way the whole thing works because I have a complex PHP class that handles registrations that comes from both browsers with JS enabled and for browsers without it. So I really need to get that session variable working right.

Link to comment
Share on other sites

I've made a simple captcha which is fully operational and I give it out, session.php holds the value of the image for the session, captcha.php shows the image.. you show the image, then compare the supplied text from the user, with the text in session.php

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

I really appreciate it but I have checked your code and I came to the conclusion that I can't adapt it to mine, so can you just help me to get mine right? Your code scared me when I saw it had references, and I already suck with pointers in C++, so I may just check them another day :P.

 

I just really need to see why when I echo the $_SESSION['captcha'] variable it is different than the captcha in the picture. I mean, both strings are the same variable, and I don't modify it in any other line after I create it.

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.