How secure are PHP sessions?

前端 未结 6 634
抹茶落季
抹茶落季 2020-12-12 17:30

I\'m primarily a C++ programmer, but I\'m trying to pick up some PHP.

Apparently the way to implement web user sessions is to store the user\'s login ID in a cookie

6条回答
  •  再見小時候
    2020-12-12 17:46

    If do this:

    $_SESSION['user'] = $username;
    

    Then $username will not be directly stored in a cookie. Instead a unique session id will be generated and stored inside a cookie.

    The info that you store in $_SESSION is only stored server side and never sent to the client. On subsequent request by the client, the server will load the session data by the id stored in the cookie when you do session_start().

    It relatively secure. The only thing that can happen is that somebody could intercept the session id and thus steal the real users session. HTTPS can prevent that from happening though.

提交回复
热议问题