In-depth resolution of whether the Session must depend on cookies. The session in php can use the cookie of the client by default (in order to distinguish it from the cookie in the general sense, I call it sessioncookie, and the cookie in the general sense is cookie) to save the session in sessi php, the client cookie can be used by default (so as to be different from the cookie in the general sense, I call it session cookie, and the cookie in the general sense is a cookie) to save the session id, but does the session in php only use session cookies?
Of course not. Otherwise, it is better to use the cookie directly to get a session. A major advantage of session is that when the client's cookie is disabled, the session id will be automatically attached to the url, so that the session variable can be remembered through the session id.
Next, I will write two files to verify that the cookie is disabled in the browser.
The code is as follows:
// The file name is test1.php.
Session_start ();
Session_register ("url ");
$ Url = "test2.php ";
Echo "goto test2.php ";
?>
The code is as follows:
Session_start ();
If (session_is_registered ("url ")){
Echo "congratulations .";
$ Url = "test1.php ";
Echo "goto test1.php ";
} Else
Echo "failed .";
?>
Enter "http: // localhost/test1.php" in the browser and move the mouse over the link to check the address on the status bar. this is not a simple "http: // localhost/test2.php ", but in this form: "http: // localhost/test2.php? Phpsessid = 6e3610949f7ded3784bc4a4dd10f879b ".
You can also view the html source file in this form:
Goto test2.php
Therefore, this is entirely the credit of php and has nothing to do with the browser. that is to say, no matter what browser session you use, it is valid, not what some people think is only useful for ie.
However, our hyperlink is the statement output by the echo statement. if the hyperlink is not included in the php tag What will happen? Let's write an example to verify it and make some modifications to test1.php:
The code is as follows:
Session_start ();
Session_register ("url ");
$ Url = "test2.php ";
Echo "goto test2.php";?>
(Html form) goto test2.php
Enter "http: // localhost/test1.php" in the browser and move the mouse over the two links to see if they are different? As you can see, the two links are exactly the same, and the session id will be automatically attached later. so you don't have to worry that the link not included in the php tag will expire, and php will not be so stupid.
However, you must first use the session_start () function to tell php to start using session, even if you only have html code in this file, such:
Gogogo
............
I remember someone said that this advantage can only be used in linux/unix. However, I used win2000p + apache1.3.17 + php4.0.4pl1 and php as the apache module. on the contrary, I switched to linux for testing, but it didn't work. in fact, an option -- enable-trans-sid at compilation controls whether this function is useful. by default, php does not enable this function during compilation. you only need to add this function during re-compilation. my configuration is apache1.3.17 + php4.0.4pl1, and php is an apache Module. After linux is re-compiled, netscape navigator4.7 can be used to pass the test (this proves that it is not related to the browser ).
Session alone cannot be used across windows. even if you enable cookie, when you have a valid session id in a window (recorded in session cookie, not in url ), when you open a new window to enter the same page, you will have a new session id, which does not affect the previous window.
To use the same session id across WindowsSpecify the session id after the urlThat is to say, if you copy the url of the window with the session id and paste it in the new window, it will still be used. knowing the principle of session id, it is not difficult to implement cross-Window sessions. we can combine cookies with Sessions,Obtain the current valid session id, record it in the cookie, and read the cookie in other Windows to obtain the current session id.
Encrypt (so as to be different from cookie in the general sense, I call it session cookie, and cookie in the general sense is cookie) to save sessi...