alexandru.topliceanu Posted January 28, 2011 Share Posted January 28, 2011 Hi, I have the following problem. I created a module for presta, in which i have a php ajax backend file that services javascript requestsI want to get a unique identifier of the session of the user.Now session id wont return anything. Presta will let me do a session start in the php backend file , in order to get a session id, but it is unique to that file, i need something to identify the frontend session. Maybe the global cookie object?Hope i made it clear. My entire system depends on this feature. Alex Link to comment Share on other sites More sharing options...
shokinro Posted January 28, 2011 Share Posted January 28, 2011 I suggest to use TOKEN functionality of PrestaShop, it is used to identify customer.The TOKEN is generated in Tools class. You can get a token by callingTools::getToken(false); Link to comment Share on other sites More sharing options...
alexandru.topliceanu Posted January 28, 2011 Author Share Posted January 28, 2011 Hi,Thanks for the fast reply. Tools::getToken( false) gives me an unique identifier for the user and the page it's on, but not the session.The same user can be loged in on different browsers( hence different session ) but the token will be the same. Link to comment Share on other sites More sharing options...
shokinro Posted January 28, 2011 Share Posted January 28, 2011 in that case, you will need to use session. You can add following line in file init.phpsession_start();then call print session_id() at any place you want the session id. Link to comment Share on other sites More sharing options...
alexandru.topliceanu Posted January 28, 2011 Author Share Posted January 28, 2011 Yes, but i am building a module for general use and disctribution, not for my own shop. Thus, I can't modify the presta core Link to comment Share on other sites More sharing options...
shokinro Posted January 28, 2011 Share Posted January 28, 2011 Yes you are right, we should try our best to avoid changing core files.But some times, you will have to do that. Make the changes minimum should be OK, that's what I am thinking. Link to comment Share on other sites More sharing options...
WDSY Posted January 31, 2011 Share Posted January 31, 2011 Perhaps include JQuery cookie in your module file?http://plugins.jquery.com/project/Cookie Link to comment Share on other sites More sharing options...
alexandru.topliceanu Posted April 19, 2011 Author Share Posted April 19, 2011 Still no ideas on how to uniquely identify a user session from within a module?I was looking at presta's way of encoding session data into cookies. Could this help ? Link to comment Share on other sites More sharing options...
alexandru.topliceanu Posted April 27, 2011 Author Share Posted April 27, 2011 Hi, i have found a fix for this.It turns out that presta doesn't use native php session support( $_SESSION array and session_* function ). Instead it uses encrypted cookies to send session data along with EACH http request/reply. Thus, instead of working with $_SESSION you must use $cookie which a singleton instance of Cookie class. You can attach any properties you like to it an use them anywhere in the session.See this post for an example: "save a session variable" Link to comment Share on other sites More sharing options...
aschaeffer Posted June 21, 2012 Share Posted June 21, 2012 Hi, I'm interested by getting a unique session id by prestashop. I just read the article about cookie, but i have one question, is the property _name of the cookie class unique? I took a look in the class but i didn't find any comment on the property to tell me if the variable is unique, or not. Link to comment Share on other sites More sharing options...
aschaeffer Posted June 21, 2012 Share Posted June 21, 2012 Looks like it's unique, according to this page : http://www.nethercottconstructions.com/en/content/53-prestashop-cookie-structure Link to comment Share on other sites More sharing options...
masoud2011 Posted December 30, 2015 Share Posted December 30, 2015 (edited) it is an old post, but I have same problem currently I have tried this Context::getContext()->cookie->checksum for me it works Edited December 30, 2015 by masoud2011 (see edit history) Link to comment Share on other sites More sharing options...
aschaeffer Posted December 30, 2015 Share Posted December 30, 2015 Did you check that the checksum change in each session? From what I remember it's always the same, but I can't test it now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now