PHP implements mixed alphanumeric verification code

王林
Release: 2023-04-08 10:18:02
forward
2830 people have browsed it

PHP implements mixed alphanumeric verification code

The verification code effect is as shown in the figure:

PHP implements mixed alphanumeric verification code

Verification code calling address: Application\Home\Controller\CodeController.class .php

Vendor('Vcode.Vcode', '', '.class.php'); 
$config = array("width" => 100, "height" => 36, "count" => 4, "str" => 2); //配置 
$vcode = new \Vcode($config); 
$vcode->getCode(); //获取验证码 
$vcode->getImg(); //输出图片 
exit;
Copy after login

(Related free learning video tutorial sharing: php video tutorial)

The verification code picture is as follows:

PHP implements mixed alphanumeric verification code
Copy after login

JS passed Add a random number Math.random() to the suffix to refresh the verification code

function changeCode(obj) { 
 obj.attr("src", '__APP__/code/?' + Math.random()); 
}
Copy after login

Check whether the verification code is entered correctly

 

function checkCode() { 
  $.post("__APP__/Code/check", {code: $("#input_code").val()}, function(data) { 
    if (data == '1') { 
      alert("验证码正确!"); 
    } else { 
      alert("验证码错误!"); 
    } 
  }, "json") 
}
Copy after login

Compare the parameter code passed by PHP verification with the verification code stored in the current session. If it is correct, it will return 1, if it is wrong, it will be -1

public function check() { 
    $code = I('post.code'); 
    if (strtolower($code) == $_SESSION["sucaihuo_code"]) { 
      echo "1"; 
    } else { 
      echo "-1"; 
    } 
}
Copy after login

Recommended related articles and tutorials:php tutorial

The above is the detailed content of PHP implements mixed alphanumeric verification code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!