Is the session still usable after the cookie is disabled in php5? Solution-php Tutorial

Source: Internet
Author: User
After the cookie is disabled in php5, can the session still be used? I did a test on two irrelevant pages a and B. & Nbsp; set the session in a and display it in B. When the session is disabled by the browser, the session can be displayed locally, but the session is not shown as mentioned above, and there is session_id or something next to the url. uploading to the unix server won't work. Q: Is the session still usable after the cookie is disabled in php5?
I did a test on two irrelevant pages a and B.
Set the session in a and display it in B.
When the session is disabled by the browser, the session can be displayed locally, but the session is not shown as mentioned above, and there is session_id or something next to the url. uploading to the unix server won't work. Puzzled



------ Solution --------------------
Php. ini, set the session. if use_trans_sid is set to 1, sessionid will be added after the connection, and the session key will be passed through the url. in this case, the client can use session even if cookie is disabled.

In addition, the browser can only disable cookies, but the session cannot be disabled. only the session key is saved in the cookie.
------ Solution --------------------
If you see an example, I think it is good. share it with you:

Session stores cookies on servers and clients.
Yes, the biggest difference between Session and Cookie is that the following is what I have organized based on code and related understanding.
Code:
A1.php
Function CookiesTest ($ newValue ){
If (! Isset ($ _ COOKIE ["CookiesTest"]) {
Setcookie ('cookiestest ', $ newValue, time () + 3600 );
Echo "CookieValue:". $ _ COOKIE ["CookieValue"];
}
}
Function SessionTest ($ newValue ){
If (! Session_is_registered ('sessiontest ')){
Session_register ("SessionTest ");
}
}
CookiesTest ("HelloCookies! ");
SessionTest ("HelloSession! ");
Echo "CookieValue:". print_r ($ _ COOKIE )."
";
Echo "CookieValue:". $ _ COOKIE ["CookiesTest"]."
";
$ SessionTest = "dd ";
Echo $ SessionTest;
Echo $ _ SESSION ["SessionTest"];
?>

A2.php

// Session_start ();
Echo $ _ SESSION ["SessionTest"];
Echo $ CookiesTest;
?>
Cookie:
(1) used to store the data used to access a page consecutively. (That is, the local Cookie value is not a global change concept in the true sense, that is, for A1.php, the corresponding COOKIE value can be called by adjusting $ _ Cookie ["XX, however, if you open an A2.php Internet Explorer and then retrieve the Cookie value, you will not be able to retrieve it! Therefore, cookies are not actually a global concept .)
(2) cookies are stored on the client and stored in the Temp directory of user WIN.

Session: (a special Cookie. The Session will also be disabled when the Cookie is disabled, but the Session can be re-obtained through redirection)
(1) it can be used to store the globally unique variables of users. For a Session, you can use Session_start () to redirect the Session and obtain the value of the Session, and perform operations without interrupting whether the Session is opened repeatedly. The above A1.php performs Session operations. if another IE is opened and Sessoin_start () is used, the corresponding Session variables will be re-enabled, that is, the global and unique true meaning is achieved.
(2) sessions are stored in the session_dir directory specified by php on the server. The above is my understanding of Session and Cookie.

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.