PHP 验证码图像
我在 PHP 表单中使用验证码图像验证器。该表单使用cookie来检查用户输入的验证码。除了使用cookie之外,还有其他方法可以做到这一点吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我在 PHP 表单中使用验证码图像验证器。该表单使用cookie来检查用户输入的验证码。除了使用cookie之外,还有其他方法可以做到这一点吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
在这种情况下,Cookie 是一个非常糟糕的主意。相反,您应该使用
$_SESSION
PHP 超全局。在验证码输入页面的顶部,添加以下内容(最小版本):session_start()
文档可以在此处。然后,当提交表单时,检查从表单提交的值是否与
$_SESSION['captchaCode']
中的值相同:请记住,这是一个非常简单、通用的值这样做的方法。如果您使用 reCAPTCHA 或 Securimg,那么它们将有自己的方法来验证它们生成的验证码。
Cookies are a very bad idea in this case. Instead, you should use a variable set in the
$_SESSION
PHP superglobal. At the top of your captcha-input page, add this (minimal version):session_start()
documentation can be found here.Then, when the form is submitted, check that the value submitted from the form is the same as the one in
$_SESSION['captchaCode']
:Do bear in mind that this is a very simple, generic way of doing it. If you're using reCAPTCHA or Securimg then they will have their own ways of validating the captchas they generate.
我不使用 cookie,您只需查看它们输入的内容是否与验证码条目数据库中的内容直接匹配;也就是说,如果您有可能的验证码数据库?
I don't use cookies, you can just see if what they enter matches directly with what you have in the database of captcha entries; that is if you have a database of possible captchas?
这是一个非常易于使用和设置的脚本。该脚本只是创建图像,但合并验证并不困难。您可以在此处下载脚本来验证验证码图像,使用 php 或 javascript 来确保发布值等于 $_SESSION['security_number'] 就完成了。
Here is a script that is very easy to use and setup. This script just creates the image but it is not tough to incorporate the verification. You can download the script here to verify the captach image use either php or javascript to make sure the post value is equal to $_SESSION['security_number'] and your done.