PHP uses session to synchronously log on to two different server websites. now there are two servers a: www. test1.comb: www.test2.com I want to log on to test1, and then log on to test2 as well. how can I write this? I have partially tested PHP using session to perform synchronous login on two different server websites.
There are now two servers
A: www.test1.com
B: www.test2.com
I want to log on to test1 and then log on to test2. how can I write this?
I have some test code as follows:
When logging on to test1, if the logon is successful, run the following command:
$ Fp = pfsockopen ("www.test2.com", 80, $ errorno, $ errormsh); // connect to the server
If ($ fp ){
$ Out = "GET/login. php? Acc = ". $ acc." & psw = ". $ psw." HTTP/1.1 \ r \ n ";
$ Out. = "Host: www.test2.com \ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
Fputs ($ fp, $ out );
Fclose ($ fp );
}
Then the login. php file in www.test2.com
$acc = $_GET['acc'];
$psw = $_GET['psw'];
$_SESSION['acc'] = $acc;
$_SESSION['psw'] = $psw;
Then I access www.test2.com
The session is empty.
Please advise! PHP session cross-origin? Login? Share:
------ Solution --------------------
If single sign-on is so easy, isn't all SSO service providers shut down?
Session uses the sessionid carried by cookies for uniqueness identification
Normal cookies cannot be cross-origin. Although some technical means can be used to implement cross-origin cookie, this is, after all, a rule vulnerability is exploited and is not desirable.
We know that if a website has an invalid cookie, a cookie file with the domain name will be left in the browser buffer at the end of browsing. When you access the website again, the last saved cookie will be sent back.
Therefore, when you access www.test1.com, try to keep a cookie file www.test2.com.
Then you can implement synchronization when accessing www.test2.com.
How to stay? Use iframe or js to access a specific file of www.test2.com on the page returned by www.test1.com
Of course, this is only the basis, and more issues need to be considered.
------ Solution --------------------
As long as www.test2.com/login.php is called on the page returned by www.test1.com
That is to say, when you access www.test1.com, you also access www.test2.com.
In this way, the cookie www.test1.com is used to access www.test1.com.
Cookie for www.test2.com for accessing www.test2.com
------ Solution --------------------
"Called on the page returned by www.test1.com" means that the request is sent from the browser so that the returned cookie will be saved by the browser.