PHP website Single Sign-on-volume one (cross two level domain name)

Source: Internet
Author: User
Tags session id php website tmp file

The session is divided into two main parts:

One, is the session data, the data is stored by default in the server's TMP file, php.ini can be changed.

Two, which is the session id,session Id that marks the session data, that session File name, session ID is randomly generated, so to ensure uniqueness and randomness, to ensure the security of the session. In general, if the lifetime of the session is not set, the session ID is stored in memory, the ID is automatically logged off after the browser is closed, and a session ID is re-registered after the page is re-requested. If the client does not disable cookies, the cookie plays the role of storing the session ID and session lifetime when the session is started.
Two different domain sites, want to use the same session, is involved in the session cross-domain problem!

There are three ways to solve this problem:
1. The following settings are provided at the beginning of the PHP page (to be preceded by any output and before session_start ())
Ini_set (' Session.cookie_path ', '/');

Ini_set (' Session.cookie_domain ', '. mydomain.com ');

Ini_set (' Session.cookie_lifetime ', ' 1800 ');

2. Set in php.ini

Session.cookie_path =/
Session.cookie_domain =. mydomain.com

Session.cookie_lifetime = 1800

3. Call the function at the beginning of the PHP page (condition same as 1)

Session_set_cookie_params (1800, '/', '. mydomain.com ');


Experimental results:

One

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5C/9F/wKiom1UeTs-izDBxAALIDsdA6tc978.jpg "title=" C1d62fe8-e673-4576-9637-1b7f962f806d.png "alt=" Wkiom1uets-izdbxaalidsda6tc978.jpg "/>


Two

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5C/9F/wKiom1UeTdORaMiEAALAOwJsBXg975.jpg "style=" float: none; "title=" De95145d-bbd2-450e-abea-4f772628cfcc.png "alt=" Wkiom1uetdoramieaalaowjsbxg975.jpg "/>



As they are but the session_id is the same, so the session data can also be shared, thus solving the simplest single sign-on.

PHP website Single Sign-on-volume one (cross two level domain name)

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.