Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Join Date
    Mar 2005
    Posts
    24
    Plugin Contributions
    0

    Default referencing $_SESSION['customer_id'] variable outside of ZenCart

    Hi,

    Is it possible to use the value of the $_SESSION['customer_id'] variable in pages outside of ZenCart?

    When I try - the value isn't available.

    Is it something to do with the scope of the variable?

    Is there anything I can do to reference it from pages outside of ZenCart please?

    Thanks,

    Andy

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    If you are seeking this in an attempt to use ZenCart functions for an html based site where you only want the add to cart and checkout fnctions and maybe others.

    This is not possible as ZenCart is not modular, and you have stumbled upon one of the major issues with trying to do this and this is sessions. For security reasons these are not static and therefore cannot be normally resused one the main session has expired.

    If you are seeking to display some specifics on another site, look at a couple of modules in the downloads area there is one for inclusion in html and I think that ideagirl is the author and another for a php page.

  3. #3
    Join Date
    Sep 2004
    Posts
    1,388
    Plugin Contributions
    4

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    Expanding on Kobra's comment, $_SESSION variables are specific to a user's session, which is a unqiue visit to the site and identified by a session id. It's not possible to use these variables on a static page without first establishing a session.

    Furthermore, session variables are limited to the domain (and sub-domain, if specified) in which they were created. This is a general web restriction for security, as sharing session variables across sites opens the possibility for hackers to steal a session and assume a person's identity on a site.

    That being said, there are ways around session limitations, but they might open up security holes as described above. You should read up on $_SESSION and the various session functions in the PHP manual to gain a better understanding.

    If you only seek to use some of Zen's functions (and not any info in the DB), you could mimic the InitSystem, loading the stuff the want at page load, and bypass the session stuff.
    Frank Koehl
    "Cleverly Disguised as a Responsible Adult"

    frankkoehl.com

  4. #4
    Join Date
    Mar 2005
    Posts
    24
    Plugin Contributions
    0

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    I'm not trying to use ZenCart functionality in a static html page. I'm using PHP pages and am familiar with PHP sessions.

    I need to get hold of the 'customer_id' session variable as I want to provide other facilities to customers whilst they have logged in to the site. I would like them to be able to update a user profile but I don't want them to have to login again if they've already logged into ZenCart. I would therefore like to use their 'customer_id' to record their profile by.

    The PHP pages I would like to use the 'customer_id' within are part of the same site as the ZenCart shop.

    So - can you tell me how I reference the session variable please within these other PHP pages?

    Thanks,

    Andy

  5. #5
    Join Date
    Sep 2004
    Posts
    1,388
    Plugin Contributions
    4

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    You could pass it via a form using POST or GET, just insert the value of $_SESSION['customers_id']. I do this on two sites where I link users' login session. I use a special link, pass the necessary variables, and perform some verification on the other side.
    Frank Koehl
    "Cleverly Disguised as a Responsible Adult"

    frankkoehl.com

  6. #6
    Join Date
    Mar 2005
    Posts
    24
    Plugin Contributions
    0

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    Yes but that would require them to click on a link or a button after they have logged in wouldn't it to pas the values within the POST?

    I just want to be able to reference the variable in a page that is outside of ZenCart at some point when they choose to accesss it in the session.

    I've tried using $_SESSION['customer_id'] as the variable in the page outside ZenCart but the value assigned to it isn't available.

    Is it a scope issue?

    Andy

  7. #7
    Join Date
    Sep 2004
    Posts
    1,388
    Plugin Contributions
    4

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    Yes, which is what myself and others were trying to explain; it's also why I used the "magic link" setup. $_SESSION is only available within the current session and defined domain.

    If you are staying within the current domain, make sure you are actually starting the session on your non-Zen page. Even when a session already exists, you must instruct PHP to continue the session on your page. Zen Cart take care of this through the stuff going on in application_top.php, so it appears invisible to you. On a custom page, you need to at least make a call to session_start() (link to function details).

    Again, do some reading. The PHP manual is invaluable for stuff like this.
    Frank Koehl
    "Cleverly Disguised as a Responsible Adult"

    frankkoehl.com

  8. #8
    Join Date
    Mar 2005
    Posts
    24
    Plugin Contributions
    0

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    Hi Frank,

    Thanks for your help.

    However - I'd like to let ZenCart look after the logging in of the user. The session variable is therefore initially created 'within' a ZenCart page isn't it rather than outside it s you mentioned?

    My PHP page outside ZenCart does use the following lines at the top of the page:

    session_cache_limiter('must-revalidate');
    session_start();

    Out of curiosity - are 'you' able to reference the value of the 'customer_id' session variable in a page outside ZenCart on your web site?

    Andy

  9. #9
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    Just got back to this...

    If your user has logged in I will assume that they are in the cart. How are they to get to this page you reference? As stated, if you generate the link to the other page from within ZenCart you can then also pass the information along.

    If this is an update to their user profile, can you not create a sidebox link to the page and in the code call for the form generation and pass the session variable along.

    I thinbk that we are trying to state that if you start this from within ZenCart you will have better luck. I can see no way or reason that a user would be on an outside page trying to do what you want without first being in the cart and logged in.

  10. #10
    Join Date
    Mar 2005
    Posts
    24
    Plugin Contributions
    0

    Default Re: referencing $_SESSION['customer_id'] variable outside of ZenCart

    The shop area is only a part of the entire web site.

    I have a navigation toolbar outside of ZenCart. There is a link within this toolbar that takes them to a page (outside ZenCart) where they can update their User Profile where they can register things they are interested in etc.

    I don't want users to have to login twice within the web site (ie. once to update their profile and once to use the shopping cart) so I'd rather use ZenCart to enable the users to login.

    I then want to use the 'customer_id' session variable as the user variable to update their profile info.

    Andy

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v150 Where is $_SESSION['customer_id'] being set?
    By jrcook416 in forum General Questions
    Replies: 4
    Last Post: 1 Aug 2012, 01:36 PM
  2. Using $_SESSION outside Zen-Cart?
    By seanbig in forum General Questions
    Replies: 3
    Last Post: 21 Dec 2010, 08:21 AM
  3. Need help adding $_SESSION variable
    By chadderuski in forum General Questions
    Replies: 4
    Last Post: 14 Jun 2010, 04:30 PM
  4. Replies: 0
    Last Post: 23 Nov 2006, 08:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg