0

我在 PHP 中有一个用户注册表单。我在页面中放置了验证码图像检查。我像这样使用它

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

在我的 javascript 中,我想用图像中生成的相同数字(来自 create_image.php 页面)来验证它。该数字也在会话变量中设置。但是当我从 SESSION 获得号码时,我得到了前一个生成的号码。但是当我发布该页面时,我得到了由 SESSION 的 create_image.php 生成的正确的一个。

那么,如何在不从 SESSION 发布该页面的情况下获得最近生成的号码?

4

1 回答 1

1

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:

  • 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/
于 2009-07-21T12:18:18.510 回答