Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Prestashop: Session cookies & login

I would like some help with the fundamentals for making a centralized logon (front office) for Prestashop - a separate logon page.

I have a Prestashop installation with multiple shops (multistore). I have tried the Webservices API but doesn't find any way to handle logins and session cookies. How do I do this?

For example: In my Prestashop I've got three shops with three different URLs, such as:

A => mydomain.com/a
B => mydomain.com/b
C => mydomain.com/c

When a customer browses to the URL, mydomain.com (top of domain) a logon page will appear.

The user logs in and gets redirected to the shop where he/she is registered.

So to get started with my project I would like know how to login a user through a page outside Prestashop. Can I load classes from PS and use them externally?

UPDATE 1: I tried to retrive cookie data from mydomain.com/login/cookie.php:

include_once('../config/config.inc.php');
include_once('../config/settings.inc.php');
include_once('../classes/Cookie.php');
$cookie = new Cookie('ps'); // Use "psAdmin" to read an employee's cookie

if(!$cookie->isLogged()){
  echo ("Please login");
  exit;
}
else{
  echo ("Logged in as: ".$cookie->customer_lastname." ".$cookie->customer_firstname);
}

Eventough I was logged in at one of my shops (mydomain.com/b) the code (mydomain.com/login/cookie.php) says I'm not logged in. What am I doing wrong

UPDATE 2: This works but just for the first shop. I'm not able to collect data from the other shops in the same shop group.

include_once('../config/config.inc.php');
include_once('../config/settings.inc.php');
include_once('../classes/Cookie.php');
$lastname=Context::getContext()->customer->lastname;

if(!Context::getContext()->customer->isLogged()){
    echo "Please login";
    exit;
}
else{
    echo "Logged in as".$lastname;
    exit;   
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

password is SALTED in prestashop config.ini.php and you might have different versions which code the cookie differently.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...