Is my understanding of PHP sessions correct?

后端 未结 3 395
广开言路
广开言路 2020-11-28 07:39

I\'ve been interested in how sessions work internally, but I have little knowledge of C (and am unsure where to look in the PHP source for this).

This is what I unde

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 08:23

    My understanding is of the internal session handling process is the following:

    When session_start is called, PHP is looking for a parameter from the client that was sent via POST, GET, or in a cookie (depending on the configuration; see session.use_cookies, session.use_only_cookies, and session.use_trans_sid) with the name of the value of session.name to use the session ID of an already started session.

    If it finds a valid session ID, it tries to retrieve the session data from the storage (see session.save_handler) to load the data into $_SESSION. If it can’t find an ID or its usage is forbidden, PHP generates a new ID using a hash function (see session.hash_function) on data of a source that generates random data (see session.entropy_file).

    At the end of the runtime or when session_write_close is called, the session data in $_SESSION is stored away into the designated storage.

提交回复
热议问题