What is the difference between Sessions and Cookies in PHP?

前端 未结 8 1871
无人及你
无人及你 2020-11-28 04:51

What is the distinction between Sessions and Cookies in PHP?

8条回答
  •  离开以前
    2020-11-28 05:12

    Cookies are used to identify sessions. Visit any site that is using cookies and pull up either Chrome inspect element and then network or FireBug if using Firefox.

    You can see that there is a header sent to a server and also received called Cookie. Usually it contains some personal information (like an ID) that can be used on the server to identify a session. These cookies stay on your computer and your browser takes care of sending them to only the domains that are identified with it.

    If there were no cookies then you would be sending a unique ID on every request via GET or POST. Cookies are like static id's that stay on your computer for some time.

    A session is a group of information on the server that is associated with the cookie information. If you're using PHP you can check the session.save_path location and actually "see sessions". They are either files on the server filesystem or backed in a database.

    Screenshot of a Cookie

提交回复
热议问题