Jump to content

Remote login to the Prestashop backend


Recommended Posts

Hi everyone!

I'm newbie on Prestashop and I'm developing a project that connects a website with the prestashop backend but I've found some problems and I don't know if what I'm looking for is possible or not.
We've a website with information of different commerces and some of them want to sell their items via Prestashop but without re login on Prestashop, directly from our website. These two projects have different databases and they are installed in different servers.

So I need to do these tasks:
- duplicate the users into Prestashop
- add a button on our website that logs the users and redirects them to the prestashop backend

I've seen the webservice of prestashop but it hasn't implemented the login option.
I've read some post on these forum and on the Internet and they have resolved it using the curl function. So I've try it with a script like this:
 

<?php

    // where I want to go
    $url =  'http://localhost/prestashop/admin9027/index.php?controller=AdminLogin';
    
    // post params of the login form    
    $post_params = array('email' => '[email protected]',
                         'passwd' => '12345678',
                         'stay_logged_in' => 1,
                         'submitLogin' => 1);
    
    //Create a curl object
    $ch = curl_init();
    
    //Set the useragent
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);    
    //Set the URL
    curl_setopt($ch, CURLOPT_URL, $url);
    
    //This is a POST query
    curl_setopt($ch, CURLOPT_POST, 1);    
    //Set the post data
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
    
    //We want the content after the query
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
    //Follow Location redirects
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_HEADER, 0);
    
    /*
    Set the cookie storing files
    Cookie files are necessary since we are logging and session data needs to be saved
    */
    curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    
        
    //Execute the action to login
    $post_result = curl_exec($ch);
    
    $info = curl_getinfo($ch);
    curl_close ($ch);
/*
echo '<pre>';
print_r($info);
echo '</pre>';
*/
    
    echo $post_result;
    
    
    // the url of the dashoboard, where the loginAdmin redirects the user
    // (that doesn't work for me)
    //header("Location: ".$info['url']);

?>

It works parcially. The problem I've found is this
- the script is on http://localhost/test/index.php
- and prestashop is on http://localhost/prestashop/index.php

 

After the redirect, the user seems to be logged correctly, but the content is showed under http://localhost/test/ and then all the menu options are wrong and fail.

 

For that I try with:

<?php
 curl_setopt($ch, CURLOPT_HEADER, 1);

...

 // $info['url'] contains the url to the dashboard, 
 // where the login redirects after the validation
 header("Location: ".$info['url']);
?>

What I'm doing wrong?
Have someone do something similar? How do you solve it?


I've spent a couple of days trying to solve it so I'll be grateful with any help. Thanks to everyone

María

Link to comment
Share on other sites

×
×
  • Create New...