Remote login into eZ Publish with Curl

Author Message

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);
"
"

Any ideas ?

"
"

Romain

"

--
Romain Dausset

rdausset@facileit.com

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

rdausset@facileit.com

http://www.facileit.com

Nicolas Lescure

Monday 08 August 2011 12:08:04 am

Look at eZUser class. You can fetch a user (using email for instance) and connect him.

I don't really know what you want to do, so I'm not sure this will solve your problem.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 29 2025 23:47:27
Script start
Timing: Jan 29 2025 23:47:27
Module start 'layout'
Timing: Jan 29 2025 23:47:27
Module start 'content'
Timing: Jan 29 2025 23:47:27
Module end 'content'
Timing: Jan 29 2025 23:47:27
Script end

Main resources:

Total runtime0.0159 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.2500151.2266
Module start 'layout' 0.00480.0023 739.476636.6719
Module start 'content' 0.00710.0072 776.148494.2969
Module end 'content' 0.01430.0016 870.445337.9766
Script end 0.0159  908.4219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002214.0576140.0002
Check MTime0.00106.3637140.0001
Mysql Total
Database connection0.00084.719310.0008
Mysqli_queries0.002012.613730.0007
Looping result0.00000.100310.0000
Template Total0.00127.410.0012
Template load0.00095.454010.0009
Template processing0.00031.907810.0003
Override
Cache load0.00063.451910.0006
General
dbfile0.003119.369580.0004
String conversion0.00000.044940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs