Multiple sessions in one instance using PHP?

后端 未结 4 1593
既然无缘
既然无缘 2021-01-15 09:44

I have a project where I would like to create two session cookies in one browser. The first session would be to uniquely identify a person, the second would be to share even

4条回答
  •  不要未来只要你来
    2021-01-15 10:21

    If you want to share information between users, using a session is not the best idea as it uses the file system. You would be better off using the database which handles all the issues of locking, concurrency etc.

    Although what you ask for is technically possibly, I would strongly recommend against it.

    EDIT

    Assuming I have understood your requirement correctly, here is how I would do it:

    1. Use session only to store session data related to that user. It could include something like:

      $_SESSION['name'] = 'test name';
      $_SESSION['groupid'] = 2;
      
    2. A MySQL DB and table with fields groupid, XXXXX (data you want to store), timestamp

    Whenever anyone updates information for a particular group id, you update the timestamp.

    Then run a simple cronjob to check if any current time - timestamp > 3600 (one hour) and you can consider that as stale and delete those records.

提交回复
热议问题