Home  >  Article  >  Backend Development  >  What should I do if the session verification code in PHP is out of sync?

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

coldplay.xixi
coldplay.xixiOriginal
2020-07-11 14:15:212486browse

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[&#39;yzm&#39;]=$yzm;

Login page:

\3d4be046353cdf42b5a24a4bc87da507

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 the session variable needs to be refreshed after setting to take effect.

We introduce the yzm.php page 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[&#39;yzm&#39;];

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!

Statement:
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

Related articles

See more