best way to pas $var from image gen to script

Ask about a PHP problem here.
Post Reply
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

best way to pas $var from image gen to script

Post by jonathon »

I've built a random generated captcha for a contact form, so It creates a random 5 letter string and then creates an image. I then call this script as an image source from my contact page. But I need to verify the correct input of the captcha. I'm using a self verifying contact form so contact.php posts to contact.php, so i'm trying to think of the best way to validate that the capctha is correct. Has anyone got any advice?
Currently i'm slightly concerned that i'll just overwrite the capctha value every time the form is validated

Thanks in advance if anyone has any good ideas
conradk
Posts: 117
Joined: Tue Jul 05, 2011 10:41 pm

Re: best way to pas $var from image gen to script

Post by conradk »

Validate the captcha value before the captcha is generated on Contact.php :)

Create a variable that stores whether or not the captcha was entered correctly. If not, just show a new captcha. If it was entered correctly, process the form values :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: best way to pas $var from image gen to script

Post by jacek »

To add to the above, make sure you do that check before the code that generates a new code. That way, if the user enters the correct code, the form will be processed before the new code is generated.
Image
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: best way to pas $var from image gen to script

Post by jonathon »

I'm not sure its possible the way I have it set up.

My verify.php file generates the random string

In my contact.php file within the <form> tags i call the script as an image so:
<img src="verify.php" />

So on that basis I can't validate the input can i? :s
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: best way to pas $var from image gen to script

Post by jacek »

You could store the key in the session to get it back to the main page.
Image
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: best way to pas $var from image gen to script

Post by jonathon »

Hmmm, yes i thought that i'd possibly have to go down the session route. Thanks for your help Jacek, I'll get on the session approach :)
Post Reply