What should I do if the session verification code in PHP is out of sync?

coldplay.xixi
Release: 2023-03-02 12:16:02
Original
2420 people have browsed it

The solution to the out-of-sync session verification code in php: introduce the [yzm.php] page, and set a form submission path on the login page. The code is [session_start();echo $_SESSION['yzm'] ;].

What should I do if the session verification code in PHP is out of sync?

Solution to the out-of-sync session verification code in php:

Verification code generation page:

for($i=0;$i<4;$i++){ $y = mt_rand(3,10); $size = mt_rand(5,8); $ran = dechex(rand(0,15)); imagestring($im,$size,(2+$i*15),$y,$ran,imagecolorallocate($im,rand(0,100),rand(0,150),rand(0,200))); $yzm.=$ran; } $_SESSION['yzm']=$yzm;
Copy after login

Login page:

\

The red code is to check whether the image in the picture can be obtained correctly. CAPTCHA, but in testing, I found that I failed in one fell swoop multiple times.

Because every time the page is refreshed, the last content is displayed. Finally, I checked online and found that thesessionvariable needs to be refreshed after setting to take effect.

We introduce theyzm.phppage for the first time on the login page. The page is not refreshed. Therefore, it is currently not possible to obtain it using$_SESSION. When we refresh this page, we obtain the last session value,

in order to test whether the guess is correct. The login page sets a form submission path. The linked page is:

session_start(); echo $_SESSION['yzm'];
Copy after login

The results are consistent.

Related learning recommendations:PHP programming from entry to proficiency

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

Related labels:
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
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!