Transfer session across server in PHP

后端 未结 6 1025
陌清茗
陌清茗 2021-01-12 03:38

I need to transfer the user session across servers. ie. If user logged in server1 and if the user exists in server2 , then I have to transfer the user session details to ser

6条回答
  •  不思量自难忘°
    2021-01-12 03:59

    I would suggest writing a custom PHP session handler or using a prebuilt session handler like ShareDance. You can store session information in a MySQL database shared amongst the two machines, a SQLite file, etc.

    There are many benefits to using PHP's built in ability to get/set session data by using session_set_save_handler() namely, that all calls to get or set from $_SESSION will work in your application code without any additional modification.

    More information can be found here: http://php.net/manual/en/function.session-set-save-handler.php

    A tutorial on writing custom session handlers (old but still relevant) is here: http://devzone.zend.com/article/141

提交回复
热议问题