简体   繁体   English

PHP验证码图片

[英]PHP captcha Image

I am using a captcha image verifier in my PHP form. 我在我的PHP表单中使用验证码图像验证程序。 The form uses a cookie to check the verfication code entered by the user. 该表单使用Cookie来检查用户输入的验证码。 Is there anyother way to do this other than using a cookie? 除了使用Cookie之外,还有其他方法吗?

Cookies are a very bad idea in this case. 在这种情况下,Cookie是一个非常糟糕的主意。 Instead, you should use a variable set in the $_SESSION PHP superglobal. 相反,您应该在$_SESSION PHP超全局变量中使用一个变量集。 At the top of your captcha-input page, add this (minimal version): 在验证码输入页面的顶部,添加以下内容(最低版本):

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

session_start() documentation can be found here . session_start()文档可在此处找到。

Then, when the form is submitted, check that the value submitted from the form is the same as the one in $_SESSION['captchaCode'] : 然后,提交表单后,检查从表单提交的值是否与$_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. 如果您使用的是reCAPTCHA或Securimg,那么它们将使用自己的方式来验证所生成的验证码。

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; 我不使用Cookie,您只能查看它们输入的内容是否与验证码条目数据库中的内容直接匹配; that is if you have a database of possible captchas? 那就是如果您有可能的验证码数据库?

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. 您可以在此处下载脚本以使用php或javascript验证验证码图片,以确保发布值等于$ _SESSION ['security_number']并完成操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM