Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Access the $_SESSION from a non-zen script

Access the $_SESSION from a non-zen script

Locked

Views: 896

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
12 Jun 2009, 5:47 PM
#1
frankderosa avatar

frankderosa

New Zenner

Join Date:
Jan 2009
Location:
Charlottesville, VA
Posts:
51
Plugin Contributions:
0

Access the $_SESSION from a non-zen script

My client wanted to be able to deliver pdf reports to customer registered in ZC, so I created an admin screen that allows them to upload the documents to the server and associate them with an account. This is all working great. Problem is, the customer wants the files to be confidential, so I cooked up a simple script to read the files from a publicly inaccessible folder. It works nicely, except that I need for this scrip to be able to read $_SESSION['customer_id'] from the session variables so that I can do a quick check in the database that the requested report belongs to the customer. I don't want to pass the session value by $_GET as a link parameter so that links can't be forged - I want this script to read the value right out of the session. This will also prevent non-logged in users from getting anywhere.

So, after that long description, how can I get access to the Zen session? I have been able to get the query factory object by including config.php, init_database.php and class.base.php. Can I include something else to initiate the zen cart session?

Thanks,
Frank

12 Jun 2009, 6:09 PM
#2
frankderosa avatar

frankderosa

New Zenner

Join Date:
Jan 2009
Location:
Charlottesville, VA
Posts:
51
Plugin Contributions:
0

Re: Access the $_SESSION from a non-zen script

Oh, hmm. How embarrassing.

As soon as I posted this I started to remember about application_top.php. In my "admin" area, which is in a folder, I couldn't require application_top because the paths are all messed up. application_top wants to be called from the base ZC folder.

So then I realized while my other stuff needs to be in that folder, my file reading script does not. So I stuck in the base folder, required application_top, and boom, it worked. I don't even need to fiddle with .htaccess files.

So, um, I hope this is helpful to anybody else who needs to score the session, or the query factory object, or use other API features in a standalone script.

Wait a sec... I could have used the chdir command...? Sigh, facepalm. Is it Friday over yet?

12 Jun 2009, 7:11 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Access the $_SESSION from a non-zen script

Thanks for the update on the solution that you used ... it can be very handy eh? :smile:

And just think how many folks you helped by laying yourself bare ... :cool: