Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20
  1. #11
    Join Date
    Sep 2004
    Posts
    1,388
    Plugin Contributions
    4

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

    Look at the session code in the Zen cart headers, includes/init_includes/init_sessions.php in particular. There you can see how the Zen Cart session is built, then just pull the necessary pieces and place them at the start of your other pages. If it's all within the same site, you should be able to call the same function files, etc. without too much modification.
    Quote Originally Posted by [email protected]
    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?
    I'm not 100% sure what you mean, but it sounds like you're asking if I can get a non-Zen Cart page on my site to see the $_SESSION['customer_id'] variable. The answer I gave above applies here, so it's a "yes." Pages within a single domain can all access the same session. So if your store is at www.mysite.com/store, those Zen variables can be seen at www.mysite.com/otherpages.

    However, mystore.mysite.com (note the subdomain) is not visible at www.mysite.com. That's the security limitation I was talking about before.
    Last edited by BlindSide; 26 Nov 2006 at 08:48 PM. Reason: spelling
    Frank Koehl
    "Cleverly Disguised as a Responsible Adult"

    frankkoehl.com

  2. #12
    Join Date
    May 2008
    Posts
    3
    Plugin Contributions
    0

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

    I found this after posting in another thread about the same issue, I believe in theory you are correct about looking at init_sessions.php.
    Having said that it also looks like an enormous amount of work as that file is filled with zen_* functions ad zen specific Definitions and from what I am initially seeing to do it is going to require either replicating/rewriting a LOT of Zen Code and causing a maintenance nightmare upon a zen-cart update.
    it it was a simple matter of doing a require_once("init_sessions.php"); that would be fine however it's a lot more complicated than that

  3. #13
    Join Date
    May 2008
    Posts
    3
    Plugin Contributions
    0

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

    OK fried my brain a little on this but I have a solution that seems to work. I'll post it after I clean it up some and maybe someone who knows what they are really doing can look at my solution and fix/make better/laugh at me or whatever.

  4. #14
    Join Date
    Apr 2008
    Location
    Winnipeg, Canada
    Posts
    13
    Plugin Contributions
    0

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

    Would you be so kind as to show an example of the Special Link. I have a sidebox with a link to an external file (dir is beside the cart) and within the same domain. I have been unsuccessful accessing variables from within the external dir.

    rene




    Quote Originally Posted by BlindSide View Post
    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.

  5. #15
    Join Date
    May 2008
    Posts
    10
    Plugin Contributions
    0

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

    If you found the solution, can you please share. I have the same problem, page is within a domain and can't access session.

  6. #16
    Join Date
    Jun 2008
    Posts
    6
    Plugin Contributions
    0

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

    I too need to find a solution to this problem also. I have zen cart installed in www.mysite.com/cart and need to access the session variables from the root of the webserver. I need to do this so that I can display a link to login or logout, shopping cart, my account, checkout from other php pages.

    Anyone else trying to do the same?

  7. #17
    Join Date
    May 2009
    Posts
    16
    Plugin Contributions
    0

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

    Hi,
    I want to use the value of the $_SESSION['customer_id'] variable in pages outside of ZenCart in the same domain.
    Pls help me on that.
    Thanks.

  8. #18
    Join Date
    May 2009
    Posts
    1
    Plugin Contributions
    0

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

    There seems to be a growing interest in this customer session solution. I am attempting the same end result, but have been unsuccessful to this point with my testing. My goal is to keep the zen cart store separate from the rest of the website pages, but would like to maintain the customer log in session throughout all the pages using a log in side box and also include a site wide shopping cart side box.

    Tonight I will be testing another possiblity using 'chdir'. I am hoping that the chdir method might help in this matter, but I am not sure how it will react with the Zen Cart sessions, as the typical php session handling rules have not applied thus far.

    If anyone else has been successful with this please feel free to post and maybe we can all get some sleep instead of endless R&D testing to find a solution.

    S

  9. #19
    Join Date
    Feb 2011
    Posts
    8
    Plugin Contributions
    0

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

    Did you ever post your solution? I am struggling with this and would be interested in how you resolved it.

  10. #20
    Join Date
    Feb 2011
    Posts
    1
    Plugin Contributions
    0

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

    I've been working with this same issue and thought I would post my solution to the problem. I also could not access any information about the users session or the shopping cart outside of my zencart store directory, so what I did was opened up an invisible page inside an iFrame, and used JavaScript to send the information I needed to the parent page. It looked something like this.

    This is the script on the page I created that I placed inside my zencart store directory. I named this "customerInformation.php". It finds out whether the user is logged in or not, what their cart total is, number of items, cart ID, security token and customer first name:

    Code:
    <script>
      <?php if ($_SESSION['customer_id']) { ?>
        parent.setValue("isLoggedIn","true");
      <?php } else { ?>
        parent.setValue("isLoggedIn","false");
      <?php } ?>
      parent.setValue("total",<?=$_SESSION["cart"]->total;?>);
      parent.setValue("totalItems",<?=$_SESSION["cart"]->count_contents();?>);
      parent.setValue("cartID","<?=$_SESSION["cart"]->cartID;?>");
      parent.setValue("securityToken","<?=$_SESSION["securityToken"];?>");
      parent.setValue("customer_first_name","<?=$_SESSION["customer_first_name"];?>");
    </script>
    Then, On the page of my website where I need to access that information, I opened customerInformation.php in an iFrame with a zero width and height so it cannot be seen, and I added this javascript code:

    Code:
    function setValue(name,value){
    	if(name == "isLoggedIn" ){		
    		if(value == "true"){
    		    // show logout button
    		} else {
    		    // show login button
    		}
    	} else if(name == "total"){
    		// display the cart total		
    	} else if(name == "totalItems"){
    		//display total items in cart
    	} else if(name == "securityToken"){
    		// do what you with with this
    	} else if(name == "customer_first_name"){
    	        // display the users name
    	}
    		
    }
    The JavaScript functions would either show or hide relevant div tags, or populate text into an area using "innerHTML". This unfortunately won't help you if you need to process the information with PHP on the server side, but if it's simply about displaying information to the user, it may be just what you need.

 

 
Page 2 of 2 FirstFirst 12

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

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