session_regenerate_id() vs session_id(randomString)

后端 未结 3 2084
说谎
说谎 2021-01-18 23:01

What is the distinct difference between session_id($randomString) and session_regenerate_id()? Both seem to change session id:

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 23:08

    in a way session_regenarate_id() includes session_id() internally.

    session_id() is a way to get or set the session identifier. It doesn't handle session sess_* files. You place it before session_start in order to indicate the session identifier. Cookie creation and session file creation are session_start work later on.

    On the other hand

    session_regenarate_id() is something that does not simply set the session identifier but also get your session data from the old sess_* file and append it to the new one (with the random id) and create a new cookie. Depending on the delete_old_session parameter in session_regenarate_id() if set to true it will delete the old associated session file, otherwise it will remain as a file but it will be empty of all session data.

提交回复
热议问题