PHP: Alternative to SESSIONS

15,616

Solution 1

Another alternative is to store session data in database in give user a cookie with your session_id. That will give you more control around sessions.

Solution 2

No, since each user session should have its one values, you need some kind of session mechanism. And PHP’s session is fine for that. You probably just need to configure it properly to meet your needs.

Solution 3

You could use some other "session" solution but that requires you to do more of the plumbing.

For example, you could use url based sessions where every url the site generates includes a sessionid. This is usually a major redesign of the site and the only time it is required is if you need to have the same session over multiple domains OR if you like to have the same computer running different sessions in different windows in the browser.

But in your case I would check why the sessions are broken, its probably a configuration issue or you have someting else that screws up the session files.

I have never had any trouble with PHP sessions, they just work ;)

Solution 4

The alternative to sessions is cookies (in fact, sessions are usually implemented using cookies). But cookies should only be used if you want to store small amounts of data.

Share:
15,616
iamjonesy
Author by

iamjonesy

Lead dev at Appointedd. Based in Edinburgh, Scotland. A few of my sites: http://findr.fm http://defaqto.io http://masquerade.eu01.aws.af.cm

Updated on June 04, 2022

Comments

  • iamjonesy
    iamjonesy almost 2 years

    I have a PHP application that relies on session variables quite a lot. After login the user get redirected to a page that executes code to set up a load of session variables depending on who the user is. The application is using data from different sources and the sessions are used to store ID numbers to query the databases.

    So when the user goes to a page that will query their asset management system their ID for that particular database is called via the session.

    I've had a LOT of problems with session variables recently. Sometimes only one session file is created during the lifetime of the app, and sometimes each session request results in a new session id (still haven't managed to find out why!).

    My question is this. Is there an alternative to using session variables for this? Like globals or some other way?

    I have a question open about my session problem here - PHP session variables not being maintaned