tags:

views:

84

answers:

1

I have a user registration form in PHP .I put captcha image check in the page.I used it like this

//img id="imgCaptcha" src="create_image.php"//

and in my javascript i want to validate this with the same number which is generated in the image (from create_image.php page) . That number was set in a session variable too. but when I get number from SESSION that time I get previous one generated number.but when I POST that page I get correct one generated by create_image.php from SESSION.

so,how can I get recently generated number without posting that page from SESSION?

+1  A: 

The problem is that the php-page with the image is loaded after the code is posted to the client, so when you try to output the number from the session, you get the result you describe.

As i see it, there are tree solutions:

  • List item
  • Generate the code in your code for the form instead, and let the create_image.php script just output it.
  • Use ajax: You can use ajax to get the number from the session after the create_image.php has been called.
  • Use an existing captcha service like http://recaptcha.net/
Torandi
Thanx.Using AJAX it's working....