PHP 验证码图像

发布于 2024-12-06 15:15:41 字数 79 浏览 4 评论 0 原文

我在 PHP 表单中使用验证码图像验证器。该表单使用cookie来检查用户输入的验证码。除了使用cookie之外,还有其他方法可以做到这一点吗?

I am using a captcha image verifier in my PHP form. The form uses a cookie to check the verfication code entered by the user. Is there anyother way to do this other than using a cookie?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暗喜 2024-12-13 15:15:41

在这种情况下,Cookie 是一个非常糟糕的主意。相反,您应该使用 $_SESSION PHP 超全局。在验证码输入页面的顶部,添加以下内容(最小版本):

session_start();
$_SESSION['captchaCode'] = /* whatever */

session_start() 文档可以在此处

然后,当提交表单时,检查从表单提交的值是否与 $_SESSION['captchaCode'] 中的值相同:

session_start();

if($_SESSION['captchaCode'] == $_POST['captchaCode'])
{
    // Do interesting things
}

请记住,这是一个非常简单、通用的值这样做的方法。如果您使用 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();
$_SESSION['captchaCode'] = /* whatever */

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']:

session_start();

if($_SESSION['captchaCode'] == $_POST['captchaCode'])
{
    // Do interesting things
}

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.

一袭水袖舞倾城 2024-12-13 15:15:41

我不使用 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?

爱本泡沫多脆弱 2024-12-13 15:15:41

这是一个非常易于使用和设置的脚本。该脚本只是创建图像,但合并验证并不困难。您可以在此处下载脚本来验证验证码图像,使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文