Accessing $user->session

akreider - February 4, 2005 - 00:45

How do I access the variables that are stored in $user->session? They got converted (serialized) into something that when I do print_r looks like
[session] => client_type|s:6:"WinIE6";sClient_type|s:6:"WinIE6";iIframe|i:1;

(And so on... I have a complex array in there.)

When I run unserialize($var) on it - it returns an empty string.

Help Still Needed - Serializing and Sessions

akreider - February 5, 2005 - 03:12

It looks like Drupal has a different serializing format than PHP does.

When I serialize some data with PHP it looks like:
s:11:"client_type";s:6:"WinIE6";s:12:"sClient_type";s:6:"WinIE6";s:7:"iIframe";i:1;

Drupal stores things in the sessions table like:
client_type|s:6:"WinIE6";sClient_type|s:6:"WinIE6";iIframe|i:1;

So when I run unserialize on $user->session - it fails.

What am I doing wrong?

Note I'm running php 4.3.4

akreider - February 5, 2005 - 03:33

Note I'm running php 4.3.4 and Drupal 4.5.

Should I upgrade the php?

Still Need Help

akreider - February 7, 2005 - 07:44

To make this even simpler, say I add $_SESSION['test']='test'; It stores it in the database as test|s:4:"test";

But then unserialize doesn't work on $user->session.

What is wrong?

OK so I haven't figured out

akreider - February 17, 2005 - 04:18

OK so I haven't figured out how to access session variables in $user->session. With help, I figured out how to access them in $_SESSION.

The trick for iframes is to follow advice I got from Neil Drumm:

Make the iframe contents be served by Drupal by writing a small module.
http://drupaldocs.org/api/4.5/file/contributions/docs/developer/examples...

Replace
print theme('page', $content);
with
print $content;
and then you don't have the header and sidebars.

Also to stay out of trouble, you might want to convert your objects into arrays before sticking them in $_SESSION. Otherwise you might run into trouble with having to define your classes before calling session_start(). Just something that happenned to me.

 
 

Drupal is a registered trademark of Dries Buytaert.