Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    22
    Plugin Contributions
    0

    Default Reading session variables outside of the zencart directory

    I'm currently building a site with an integrated Zen Cart store. The homepage has to be separate from the store, so I've installed Zen Cart in a subdirectory called 'shop/'

    I need to add a login/logout button on the homepage which links to Zen Cart. The link part works fine, the problem is detecting if the user is logged in or not, so I can display the relevant button.

    I assumed I could just check the session to determine this, but it appears to be easier said than done.

    I've had a look at Zen Carts session code, but like most things Zen, it's massively complicated and spread across countless files.

    I imagine it's just a matter of telling the server which session I want. Any ideas to how I could accomplish this?

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

    Default Re: Reading session variables outside of the zencart directory

    The homepage has to be separate from the store
    "has to" is most likely want to - - and usually no good reason
    Check Ajeh's recommendation
    http://www.zen-cart.com/forum/showthread.php?t=137413
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Oct 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: Reading session variables outside of the zencart directory

    The shop is not the primary function of the site, many people will go there simply for information about the organisation.

    It's a bit like if you go to apple.com they don't immediately take you to the shop... the option is just there if you want it.

    I've made a temporary fix by putting the customers id in the address bar - if they leave the shop section of the site, when logged-in. This gets passed around between the pages until they log-out again... so the rest of the site knows what's going on.

    I'd be greatful if anyone can answer my original question...

    I can get the correct session id, I just can't seem to get any values out of it.


    edit:
    Oops sorry didn't see the link
    Last edited by refreshmentshop; 21 Sep 2009 at 03:25 PM.

  4. #4
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: Reading session variables outside of the zencart directory

    The problem is that its not all that easy.

    While its not that difficult to start a session on your non-shop page that can potentially have access to Zen Carts native session data there are lots of gotchas.

    First the easy part.

    Doing something like this.

    <?php
    session_name('zenid');
    session_start();

    should get you some way there.

    Now for the gotchas.

    PHP needs to store its session information somewhere. Zen Cart will store this information either in the filesystem or the database.

    If you have session handling set to store session data in the database, then to access that information on non-shop pages you are going to have to dupllcate a lot of logic on your non-shp pages to get at that information.

    If session handling is set to file then its a little more straight forward, as all you need then do is tell PHP where on the file system the session info is being stored.

    Zen cart does something like this

    session_name('zenid');
    session_save_path(SESSION_WRITE_DIRECTORY);
    session_start();

    where SESSION_WRITE_DIRECTORY is the path to the session directory usually the 'cache' directory of your zen cart install.

    Another possible gotcha. All of the above also assumes your customers have cookies enabled. If that's the case all well and good. In most cases you can assume such.
    If its not the case, then every time your customer moves between shop and non-shop pages then the session will be lost (ie if they are logged in they will be logged out)

    Zen Cart gets round that problem by passing the session id in the URL, again if you want to cater for customers who block cookies, then you are going to have to duplicate Zen Cart logic in that respect.

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

    Default Re: Reading session variables outside of the zencart directory

    The shop is not the primary function of the site, many people will go there simply for information about the organisation.

    It's a bit like if you go to apple.com they don't immediately take you to the shop... the option is just there if you want it.
    Apple's main intent is not online business...

    Org info - this is what ezpages are for and would sovle the sessions issue

    ZenCart can be a sort of CMS in addition to a cart
    Zen-Venom Get Bitten

  6. #6
    Join Date
    Oct 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: Reading session variables outside of the zencart directory

    @wilt

    Thanks for the detailed response. I was beginning to realise it was a lot more complex than I originally thought.


    @kobra

    Apple's main intent is not online business...
    Yeah, it's the same for this company.

    I did consider integrating the rest of the site into zencart as custom pages. One problem this presented was having to replace the zencart homepage (sidebars etc) with a totally different page, and then bringing it all back, when you actually go to the shop page.

    If you can think of a simple way of doing that, you're a better man than me...

 

 

Similar Threads

  1. Replies: 6
    Last Post: 15 Apr 2011, 08:56 PM
  2. Reading $_Post variables from checkout_shipping page?
    By pcaliban in forum General Questions
    Replies: 8
    Last Post: 3 Nov 2010, 07:21 PM
  3. Zencart and session variables..?
    By flyingCoyote in forum General Questions
    Replies: 0
    Last Post: 17 Jan 2008, 02:58 AM
  4. Using Zencart Info Outside of the zencart Directory
    By thisandthat in forum General Questions
    Replies: 6
    Last Post: 29 Dec 2007, 05:29 PM
  5. how do include a file outside the zencart directory
    By apathy in forum General Questions
    Replies: 9
    Last Post: 17 Dec 2007, 08:02 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR