Php verifies the invalid session solution. php verifies the session
This article describes how to verify invalid session in php. Share it with you for your reference. The specific method is as follows:
I. Problems
It took a long time to configure the apache + php environment today. Later, it succeeded, but found that the verification code image can be generated. during login verification, it was found that the session was empty and there was no value.
Ii. Solution
Environment: apache + php
The program code is as follows:
Copy codeThe Code is as follows: <input name = "username" type = "text" class = "input" id = "username">
<Input name = "password" type = "password" class = "input" id = "password">
<Input name = "ver" type = "text" class = "input1" id = "ver" size = "5">
Process the post. php file after submission
Copy codeThe Code is as follows: if ($ _ SESSION ['ssioner]! = $ Ssever ){
Echo ("<script> alert ('verification code must consist of four digits! '); History. back (); </script> "); exit;
}
The result shows that the verification code must be composed of four digits and the output session is printed:
Copy codeThe Code is as follows:
Echo $ _ SESSION ['ssioner'];
Exit;
It was always blank, so I thought of a session file directory configured in the php environment. Now we find the php. ini configuration file
Upload_tmp_dir
This directory is found to be
Upload_tmp_dir = "D: \ www.jb51.net \ tp"
I checked my d disk and found that there were only www.jb51.net files but no tp directory. In this case, I found the problem. At that time, I created a tp directory, restart apache and you will find the sess_i40gl0p4hfep5r69j67o1k26d01 file in the tp directory. Then, you can log on again.
I hope this article will help you with PHP programming.
How can php sessions be invalid ??
<? Php
SESSION_START ();
If (isset ($ _ POST ['name']) {
$ _ SESSION ['name'] = 'test ';
}
Print $ _ SESSION ['name'];
?>
In <? Add SESSION_START () to php. If it is not started, how can this problem be solved? Think about your practice, just assign a value to it temporarily.
Solution for delaying session verification code and display in php
First, you can debug your project and print your verification code information in the class. Whether it is consistent with the verification code displayed on the page. Generally, there is no problem. Unless it is referenced multiple times.
I have previously written a verification code function. You can refer to: Baidu php Verification Code pooy. You can find the article I wrote earlier.