yesterday i asked o complex question about it but noone answer it so i want to ask as simply i can.
I want to login user to site b when he logs in site a. ( i want to somekind sso wordpress->lms platform)
im trying to do it with cURL and i use code like this:
$username="...";
$password="...";
$url="...";
$cookie="cookie.txt";
$postdata = "login=".$username."&password=".$password;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
This script works fine but i have 2 issues: - script redirect me to a siteB and log me in but when i click on some link in siteb i get info im not loged in ( i fink that cURL is loging in the server not user). I guess here i need to read cookie from txt file and add it to user browser ?
If anyone was doing something similar please point me in a right direction becouse im stuck on this for 2 days ;(
Here is a link to my previous answer where i explained this case in details:
Wordpress SSO with Chamilo LMS - log in to chamilo in background
You can't set a cookie on behalf of another person for a different domain using a non-browser plugin.
Think about it for a bit... you go to a website and they log you into your bank account w/o showing you that they've done so... how would you feel? Browser security makes that extremely difficult on purpose.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.