Cookies are good, but some client browsers will disable cookies, which will result in the failure or error of the program you rely on, so how can PHP use the session again if the user closes the cookie? There is still some way.
1, set php.ini Session.use_trans_sid = 1 or open the ENABLE-TRANS-SID option, let PHP automatically pass the session ID across pages.
2, manually pass the URL value, hide the form passed session ID.
3, file, database and other forms to save session_id, in the process of cross-page manual call.
Route 1 illustrates:
s1.php
<? PHP Session_Start (); $_session [' var1 ']= "source enthusiasts"; $url= "<a href=". "" S2.php "> Next </a>"; Echo $url ;? >
s2.php
<? PHP Session_Start (); Echo "The value of the passed session variable VAR1 is:". $_session [' var1 '];? >
Run the above code, in case the client cookie is normal, should be able to get the result "source fan".
If the client's cookie is closed at this time, it is estimated that the result is not available, you can set the php.ini in Session.use_trans_sid = 1 or at compile time to open the--ENABLE-TRANS-SID option ", at this time again can get results" source fan "
Route 2 illustrates:
s1.php
<? PHP Session_Start (); $_session [' var1 ']= "source enthusiasts"; $SN session_id (); $url= "<a href=". "" S2.php?s= ". $sn. "" > Next </a> "; Echo $url ;? >
s2.php
<? PHP session_id ($_get[' s ']); Session_Start (); Echo "The value of the passed session variable VAR1 is:". $_session [' var1 '];? >
The basics of how to hide a form are the same.
Route 3 Example: login.html
Public "-//w3c//dtd HTML 4.01 transitional//en" >Please login:<form name=" Login "method=" POST "action=" mylogin1.php "> username : <input type=" text "name=" name "><br> password : <input type=" password "name=" pass " ><br><input type= "Submit" value= "Login" ></form></body>
mylogin1.php
<?PHP$name=$_post[' name '];$pass=$_post[' Pass '];if(!$name|| !$pass) {Echo"User name or password is blank, please <a href=" login.html "> re-login </a>"; die();}if(! ($name= = "Youngong" &&$pass= = "123") {Echo"The user name or password is incorrect, please <a href=" login.html "> re-login </a>"; die();}//Registered UsersOb_start();Session_Start();$_session[' User ']=$name;$psid=session_id();$fp=fopen("E:\tmp\phpsid.txt", "w+";fwrite($fp,$psid);fclose($fp);//authentication successful, related operationsEcho"Signed in <br>";Echo"<a href=" mylogin2.php "> Next </a>";?>mylogin2.php
<?PHP$fp=fopen("E:\tmp\phpsid.txt", "R";$sid=fread($fp, 1024);fclose($fp);session_id($sid);Session_Start();if(isset($_session[' User ']) &&$_session[' User ']= ' laogong ' {Echo"Logged in!";}Else {//successful login for related operationsEcho"Not logged in, not authorized to access";Echo"Please <a href=" login.html "> Login </a> after browsing"; die();}?>Please turn off cookie re-test, username: youngong Password: 123 This is the file to save the session ID, the file is: E:\tmp\phpsid.txt. As for the use of the database method, it does not give an example, similar to the way the file is manipulated. The above method has a common point, is to get the session ID on the previous page, try to pass to the next page, the next page of the Session_Start (), before adding code session_id (pass the session ID); I hope to provide you with some reference.
Workaround for PHP to invalidate the session when the client disables cookies