Zen Cart Logo
Forums / Contribution-Writing Guidelines / reading value column in sessions table

reading value column in sessions table

Locked

Views: 3,170

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
14 Aug 2008, 2:31 PM
#1
ajdrew avatar

ajdrew

New Zenner

Join Date:
Aug 2008
Posts:
2
Plugin Contributions:
0

reading value column in sessions table

I wrote a script which reads $_COOKIE['zenid'] and configuration.php, looks up the value column in the sessions table and returns that value. At first glance, the content of the value column looks like a long and winding string. Rather than take the time to turn this string into the variables I need (like user name and id number), I figure a routine already exists within Zen Cart for extracting the information.

Can somebody point me in the right direction?

14 Aug 2008, 3:10 PM
#2
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: reading value column in sessions table

It's a string because you can't store arrays and objects directly into a file or the database.

(I think) you can convert it back into an array like this:

$session_array = unserialize(base64_decode($stored_session_string));

But are you sure you need the stored session data? Depending on what you want it might be easier to use $_SESSION[]

14 Aug 2008, 9:06 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: reading value column in sessions table

What exactly are you intending to use this information for?

19 Aug 2008, 7:12 PM
#4
ajdrew avatar

ajdrew

New Zenner

Join Date:
Aug 2008
Posts:
2
Plugin Contributions:
0

Re: reading value column in sessions table

Thank you. My idea was security. I am not very familiar with php's sessions and something in my mind said I should verify that the information stored locally matched the db (or file) information and the cookie information (if available).

Example:

Where $sessiondata is taken from the stored session.

$stored_session_array = session_decode($sessiondata);

I –think- I can now ensure things like $stored_sesion_array[customers_ip_address], $_SESSION[customers_ip_address], and $_SERVER['REMOTE_ADDR'] are all the same.

If I am barking up the wrong tree, please do let me know. My goal is just to get the session information (customer ID n such) in a reliable way. Is this redundant? Do you think I should just take $_SESSION variables and trust them as good? PHP docs do claim it works fine.