The session in PHP can by default use the client's cookie (in order to distinguish it from the ordinary cookie, which I call a session cookie, a cookie in the ordinary sense) to save the session ID, But can the session in PHP only use session cookies?
Of course not, otherwise why also get a session out, rather than directly with a cookie. One of the great advantages of the session is that when the client's cookie is disabled, the session ID is automatically appended to the URL so that the session ID to remember the session variable.
Below I write two files to confirm, first set in the browser to disable cookies.
Copy the Code code as follows:
File name is test1.php
Session_Start ();
Session_register ("url");
$url = "test2.php";
echo "Goto test2.php";
?>
Copy the Code code as follows:
Session_Start ();
if (session_is_registered ("url")) {
echo "Congratulations.";
$url = "test1.php";
echo "Goto test1.php";
} else
echo "failed.";
?>
Now enter "http://localhost/test1.php" in the browser, move the mouse over the link to see the address on the status bar, not the simple "http://localhost/test2.php", but this form: "/http localhost/test2.php?phpsessid=6e3610749f7ded3784bc4a4dd10f879b ".
You can also view the HTML source file, which is in this form:
Goto test2.php
So this is entirely the result of PHP, and browser-independent, that is, no matter what browser you use the session is valid, and not some people think only for IE useful.
However, our hyperlinks are statements that are output by the Echo statement, what if the hyperlinks are not included in the PHP tag ? or write an example to verify that the test1.php is slightly modified:
Copy the Code code 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 there is a difference? You can see that two links are exactly the same, followed automatically by the session Id. So you don't have to worry about the links that aren't included in the PHP tags, PHP is not so stupid.
But be aware that you must first use the Session_Start () function to tell PHP to start with the session, even if you have only HTML code in this file, such as:
GoGoGo
............
Remember someone said this advantage can only play out under the Linux/unix, and I use the win2000p+apache1.3.17+php4.0.4pl1,php for the Apache module way, but still can. On the contrary, I went to Linux to go to the test instead of the. In fact, an option at compile time--ENABLE-TRANS-SID controls whether this feature is useful or not. This feature is not turned on when compiled by default in PHP. Just add it when you recompile. My configuration is apache1.3.17+php4.0.4pl1,php for Apache module mode, after Linux recompile with Netscape navigator4.7 test can pass (this is more proof and browser-independent ).
Only the session can not be used across windows, even if you enable cookies, when you have a valid session ID in a window (recorded in the session cookie, not the URL), and then open a new window into the same page, You will re-own a new session ID, which is not affected by the previous window.
To use the same session ID across Windows, you can only specify the session ID after the URL, that is, if you copy the URL of the window with the session ID, paste it in the new window, or still use it. I know the session. ID of this principle to achieve cross-window session is not difficult, you can combine the cookie with the session, first get the current valid session ID, and then record it in a cookie, The current session ID can be obtained by reading the cookie in the other window.
http://www.bkjia.com/PHPjc/328096.html www.bkjia.com true http://www.bkjia.com/PHPjc/328096.html techarticle the session in PHP can by default be using the client's cookie (in order to distinguish it from the ordinary cookie, which I call a session cookie, a cookie in the ordinary sense) to save Sessi ...