Zen Cart Logo
Forums / General Questions / Accessing user login & session info from outside zencart

Accessing user login & session info from outside zencart

Views: 5,980

Results 1 to 7 of 7
11 Jul 2006, 10:58 PM
#1
mav avatar

mav

New Zenner

Join Date:
Jul 2006
Posts:
2
Plugin Contributions:
0

Accessing user login & session info from outside zencart

I am trying to make it possible for pages on my site that aren't in my zencart system to be able to access Zencart session information.

For example, my Zencart store is at MYURL/store. I would like to be able to have my MYURL/index.php (or some other file in another directory) to say something like "Logged in as USERNAME", if the user is logged into the store. Also i will want to use the zen_href_link and other such functions.

including 'application_top.php' in a file that is not in the zencart directory leads to the expected path errors. so i created outside.php in the zencart root directory, which just reads to see if someone is logged in:

<?php
    $curdir = getcwd();
    if (chdir(dirname(__FILE__))) {
		require('includes/application_top.php');
		if (isset($_SESSION) && isset($_SESSION['customer_id'])) {
			?>
			Logged in as <?= zen_output_string_protected($_SESSION['customer_first_name']); ?><br>
			<a href="<?= zen_href_link(FILENAME_LOGOFF, '', 'SSL'); ?>">Log Off</a>
			<a href="<?= zen_href_link(FILENAME_ACCOUNT, '', 'SSL'); ?>">Account Manager</a>
			<?php
		} else {
			?>
			Not logged in<br>
			<a href="<?php echo zen_href_link(FILENAME_LOGIN, '', 'SSL'); ?>">Log In</a>
			<?php
		}
		chdir($curdir);
	}
?>

opening this file in a browser works as expected. however, if i try to require that file from outside the zencart directory, i get this error:
Fatal error: Call to a member function on a non-object in includes\classes\db\mysql\query_factory.php on line 103

obviously i don't want to go changing things in the zencart core stuff, since this error is just because i am doing something outside the lines.

is there an easier way to access this login info? maybe instead of loading application_top.php, would loading one of the sub-pages work?

16 Oct 2006, 10:38 AM
#2
stehodges avatar

stehodges

New Zenner

Join Date:
Jun 2005
Posts:
52
Plugin Contributions:
0

Re: Accessing user login & session info from outside zencart

Any progress on this?

I succeeded in doing this for 1.2.6 Zen Cart, but things seem to have changed quite a bit in 1.3.

All i did previously was take the relevant parts of application_top.php i needed to access from outside the zen directory and create another php file - as MAV describes above.
These carried the session etc and allowed me to use the login session to provide my account links, or if there was no session, to provide a login link which redirected back to whichever static page was used once logged in.

Cant achieve this on 1.3 so far. Any tips?

18 Oct 2006, 3:08 PM
#3
stehodges avatar

stehodges

New Zenner

Join Date:
Jun 2005
Posts:
52
Plugin Contributions:
0

Re: Accessing user login & session info from outside zencart

anyone help on this?

3 Feb 2008, 1:51 PM
#4
tingsryd avatar

tingsryd

New Zenner

Join Date:
Jan 2008
Posts:
5
Plugin Contributions:
0

Re: Accessing user login & session info from outside zencart

How do you find the variables such as "first name" to include in this script?

E.g. $_SESSION['customer_first_name']

I want to include street address and city as well...

4 Feb 2008, 10:42 AM
#5
mypashop avatar

mypashop

New Zenner

Join Date:
Oct 2007
Location:
France &amp; Luxembourg
Posts:
37
Plugin Contributions:
0

Re: Accessing user login & session info from outside zencart

in my case i have the same need, and have similar problems.

for the payment process to complete
the response is stored and the customer redirected

however, When the gateway sends back success/fail messages,

the payment process doesn´t continue,
instead sends the gateway to a session expired page.

requiring / including application top results in errors in my case as well.

22 Feb 2008, 12:41 AM
#6
scanf avatar

scanf

New Zenner

Join Date:
Dec 2007
Posts:
1
Plugin Contributions:
0

Re: Accessing user login & session info from outside zencart

I am trying to make it possible for pages on my site that aren't in my zencart system to be able to access Zencart session information.

I am looking for the same answer. This is getting to be a real pain in the back side for something that should be so simple.

15 Apr 2011, 7:56 PM
#7
sloj avatar

sloj

New Zenner

Join Date:
Feb 2007
Location:
San Luis Obispo
Posts:
10
Plugin Contributions:
0

Re: Accessing user login & session info from outside zencart

The session cookie is zenid
if you store the session in the db then you can query for the session sesskey = '$_COOKIE['zenid']'

You then need to unserialize the value.

Totally enabled us to create a single sign on solution for site.