Zen Cart Logo
Forums / General Questions / How Do I Access $_SESSION Variables in an AJAX-Called PHP Script?

How Do I Access $_SESSION Variables in an AJAX-Called PHP Script?

Locked

Views: 3,300

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
21 Apr 2010, 12:32 AM
#1
itwasntme avatar

itwasntme

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

How Do I Access $_SESSION Variables in an AJAX-Called PHP Script?

I'm developing a custom page for a client that's going to be using AJAX to call a PHP script. I'm having no luck so far in figuring out how to securely access session variables and to add new ones in the custom PHP script. Using session_start() doesn't start the existing Zen Cart session, and although I tried passing the existing session_id to the script, that's not secure and wasn't working either.

I've seen a few posts that used some fairly complex workarounds that I prefer not to use. is there a straightforward way of getting session variables and setting new ones in a custom PHP script called via an AJAX post or get with Zen Cart that someone has had success with and is secure?

I'm using Zen Cart 1.3.8a and JQuery's AJAX classes.

TIA

21 Apr 2010, 5:37 PM
#2
itwasntme avatar

itwasntme

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: How Do I Access $_SESSION Variables in an AJAX-Called PHP Script?

I finally figured this out. :clap:

Here's the relevant code to put at the top of the outside file your AJAX call is sent to:

require('../includes/configure.php');
ini_set('include_path', DIR_FS_CATALOG . PATH_SEPARATOR . ini_get('include_path'));
chdir(DIR_FS_CATALOG);
require_once('includes/application_top.php');