homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Alternate ways of organising sessions
I don't like cookies and query strings even less!

 11:21 am on Mar 28, 2005 (gmt 0)

I've recently joined the php crowd and have until now been working with my own systems.

In my old system sessions where recorded in a database usign a combination of user_agent, IP and a timeout to follow a visitor around the site, trying to avout proxy and NAT issues. Not a perfect system, but good enough for most purposes and more robust then cookies and less intrusive then query strings.

Could I use PHP session variables using my own session tracking mechanism? In other words, can I get my session ID from my database and forward it to the PHP session handler and access ressources from that session?

I want to take advantage of the resource savings that come with storing things like database connections and file handles in sessions variables.

How can I get the current session ID and how can I set it?




 3:06 pm on Mar 28, 2005 (gmt 0)

You need a custom session handler. Take a look at some ready examples: at Zend (http://www.zend.com/zend/spotlight/code-gallery-wade8.php) or DB_eSession (search for this term at Google) class.


 9:39 pm on Mar 28, 2005 (gmt 0)

Outside of cookies or the query string about your only other option is to embed the session id in a hidden form variable. Somehow you have to make the connection/relation when using HTTP. Personally, I prefer using cookies.

Anyway, the zend tutorial mentioned is a decent read and can be found on the PHP manual page for session_set_save_handler() [php.net].


 10:06 pm on Mar 28, 2005 (gmt 0)

You misunderstood. I HAVE the method of keeping track of a session, using a database and a combination of IP/user_agent and timeout.

What I need is a way of injecting my own sessionid into the php session system.

Something like getNewSessionID(), and LoadSessionWithThisID() if you know what I mean?



 10:10 pm on Mar 28, 2005 (gmt 0)

Well, if the method being used is a cookie you could assign the session_name() [php.net] before you start the session.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved