What to do if the verification code is out of sync in php

藏色散人
Release: 2023-03-13 10:24:01
Original
1502 people have browsed it

The verification code in php is not synchronized because when the page loads the login.php page, the loading of the image is asynchronous with the loading of other tags, so other tag information is loaded first, and then the image is loaded.

What to do if the verification code is out of sync in php

##The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

## What should I do if the verification code in #php is not synchronized?

Perfect solution to the problem of PHP verification code session being out of sync

Every developer has experienced the feeling of being tortured by strange phenomena. What should I say? I tried to find the reason but couldn't find it, and I tried to solve it but couldn't. Next, let's talk about the weird PHP verification code. .

Let me give you a picture first, I believe you may also look familiar. .

What to do if the verification code is out of sync in phpYou will find that the two values ​​​​are actually different. How to verify that they are different? ? ? ? ?

Ever since, I found the reason on the Internet: when the page loads the login.php page, the loading of the image is asynchronous with the loading of other tags, so other tag information is loaded first, and then src is loaded ( Picture), out of sync causes the "verification code" to be out of sync as well.

Now that I know the reason, as a newbie, I still don’t know how to start after reading the solutions written by others. .

Finally, by chance, I found the answer from a project. .

Actually, the solution is very simple. Don’t worry about whether the displayed values ​​are the same or not. For example. .

login.php Login page

<form action="login_check.php" method="post">
验证码:
<input name="checkcode" type="text" /><img src="yan.php" alt="看不清?点击更换"    style="max-width:90%" onClick="this.src=this.src+&#39;?&#39;"  />//yan.php是生成验证码的页面。
</form>
Copy after login

login_check.php Verification page

<?php 
    session_start();//开启session
    $checkcode= strtolower($_POST["checkcode"]);//获取验证码文本框的值
    echo $checkcode;//输出验证码文本框的值
    echo $_SESSION[&#39;VerifyCode&#39;]//输出yan.php输出的值
?>
Copy after login

After submission, you will be surprised to find that if I enter in login.php If the values ​​of the generated verification codes are the same, then the two values ​​output in login_check.php will have the same letters except for the different case.

Of course we can solve the capitalization problem.

Speaking of this, I believe that the problem of out-of-synchronization has been solved

Of course, I know that some people who are most striving for perfection like to use ajax. The screen will flicker back and forth according to personal preference. , it doesn’t look very good, but if you use ajax, don’t submit it to this page, otherwise it will not be verified. There is no problem in asynchronous verification through an external file.

Recommended learning: "

PHP Video Tutorial

"

The above is the detailed content of What to do if the verification code is out of sync in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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 admin@php.cn
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!