Forums / Developer / Remote login into eZ Publish with Curl

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.

eZ debug

Timing: Jan 17 2025 23:50:22
Script start
Timing: Jan 17 2025 23:50:22
Module start 'content'
Timing: Jan 17 2025 23:50:23
Module end 'content'
Timing: Jan 17 2025 23:50:23
Script end

Main resources:

Total runtime1.4066 sec
Peak memory usage4,096.0000 KB
Database Queries197

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 587.8125180.8359
Module start 'content' 0.00511.2628 768.6484563.9219
Module end 'content' 1.26790.1386 1,332.5703336.7734
Script end 1.4065  1,669.3438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.2956210.0002
Check MTime0.00150.1036210.0001
Mysql Total
Database connection0.00080.058110.0008
Mysqli_queries1.325294.21391970.0067
Looping result0.00220.15991950.0000
Template Total1.379898.120.6899
Template load0.00200.144520.0010
Template processing1.377897.951320.6889
Template load and register function0.00020.015610.0002
states
state_id_array0.00080.056210.0008
state_identifier_array0.00160.111920.0008
Override
Cache load0.00170.1242300.0001
Sytem overhead
Fetch class attribute can translate value0.00120.085030.0004
Fetch class attribute name0.00160.116660.0003
XML
Image XML parsing0.00270.195130.0009
class_abstraction
Instantiating content class attribute0.00000.001280.0000
General
dbfile0.00450.3200330.0001
String conversion0.00000.000330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 20
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs