Home > Article > Backend Development > 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?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.
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. .
You 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+'?'" />//yan.php是生成验证码的页面。 </form>
login_check.php Verification page
<?php session_start();//开启session $checkcode= strtolower($_POST["checkcode"]);//获取验证码文本框的值 echo $checkcode;//输出验证码文本框的值 echo $_SESSION['VerifyCode']//输出yan.php输出的值 ?>
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 TutorialThe 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!