Romain Dausset
|
Friday 05 August 2011 11:25:16 am
Hello, I'm trying to authenticate a user from a distant site into eZ Publish with Curl, then redirect the user to this eZ Publish site ... I use the following code but it doesn't work :
"
$postfields = array();
$postfields["LoginButton"] = "submit";
$postfields["Login"] = $login;
$postfields["Password"] = $password;
$postfields["Cookie"] = true;
$url = $site_distant . "/index.php/user/login";
//$useragent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$useragent = "eZ publish";
$referer = $url;
//Initialise une session CURL
$ch = curl_init($url);
//CURL options
curl_setopt($ch, CURLOPT_POST, 1);
//On poste les données du tableau $postfields
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//On définit un useragent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//On passe un referrer ici on passe la même page $url
//curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
//on récupère le contenu de la page de résultat de la soumission dans une chaine
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// en cas de redirection
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Page de résultats et fermeture de session
$result = curl_exec($ch);
curl_close($ch);
header("location: ".$site_distant);
"
--
Romain Dausset
[email protected]
http://www.facileit.com
|
Nicolas Lescure
|
Friday 05 August 2011 2:14:04 pm
Hi, If the request is done with curl, the server A make the post request to the server B. So the session is created between the 2 servers, not between the server B and the user. Maybe you need an Ajax request ?
|
Romain Dausset
|
Sunday 07 August 2011 8:05:09 am
Hi, Thanks for the reply, I can't use javascript, i need to authenticate from php. Do you know if there is a way to create the login session manually in eZ Publish ? Romain.
--
Romain Dausset
[email protected]
http://www.facileit.com
|