Whether the Session must depend on cookies

Source: Internet
Author: User
Tags goto session id
Does Session depend on cookies?
Www.ouryh.net Galaxy technology online tutorial time: Author: Unknown Source: unknown author: 36

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 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 file name is test1.php.
Session_start ();
Session_register ("url ");
$ Url = "test2.php ";
Echo "<a href = $ url> goto test2.php </a>
";
?>
<? // The file name is test2.php.
Session_start ();
If (session_is_registered ("url ")){
Echo "Congratulations.
";
$ Url = "test1.php ";
Echo "<a href = $ url> goto test1.php </a>
";
}
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. The source file format is as follows:
<A href = "test2.php? PHPSESSID = 6e3610949f7ded3784bc4a4dd10f879b "> goto test2.php </a>
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:
<?
Session_start ();
Session_register ("url ");
$ Url = "test2.php ";
Echo "<a href = $ url> goto test2.php </a>
";
?>
<A href = "test2.php"> (in Html format) goto test2.php </a>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.