By j_ten_man on
How can you use the current Session in a module? Also, how can you use cookies? I can't get $_SESSION or $_COOKIE to work...
How can you use the current Session in a module? Also, how can you use cookies? I can't get $_SESSION or $_COOKIE to work...
Comments
I haven't dealt with
I haven't dealt with sessions in drupal, but it seems like sess_read would work
-Craig Jackson
-Web Developer
How does this work??
I am not quite sure how this works. How do I get values out of the session that I need. just like this: sess_read('foo') and sess_write('foo', 'bar')? This kills the session when I try doing this. I am confused how this works.
What about just using
What about just using $_COOKIE[session_name()]?
-Craig Jackson
-Web Developer
My fault
Ok. I had some logic wrong in my page, so the sessions do work. $_SESSION['foo'] will work for both saving and retrieiving. Thanks for your help.
I don't understand how you
EDIT: I guess you had edited your previous post. You can disregard this since it is now working for you.
I don't understand how you can't get the session. So, maybe I need more explanation on what you are doing. But, some problems that people have with cookies is
1.) When you set a cookie, it will not be available until the next page load. However, you can just set the array in the global $_COOKIE['your_cookie'] variable too, and then if you use $_COOKIE['your_cookie'] in the future it will have the stored info.
2.) Set your path to root '/' on the cookie to ensure you can receive it on all pages on the site.
3.) Not setting the cookies expiration will only store the cookie until the browser is closed.
-Craig Jackson
-Web Developer