This is a very simple concept called sessions.
When you visit facebook, he reads unique information sent to him through the connection, such as IP address, browser and some other secondary information, when this information is combined, a unique identifier is created.
this unique identifier is then stored in a file as follows:
d131dd02c5e6eec4693d9a0698aff95c.session
Therefore, when you log in with your credentials, the application adds information to this file, such as the last activity, etc.
When you leave and return, facebook will then read the information sent with each request, then add everything together and create a unique hash, if this hash exists in its storage system, it will open it and read the contents and know exactly who you are.
all this is combined with cookies, a unique hash is sent back to the browser and stored in the cookie folder, this cookie is sent back to facebook with each request.
PHP handles this internally for you, so just start it and run it: http://php.net/manual/en/features.sessions.php
Here is an example that can help you understand the concept a little more.
<?php session_start(); if(!isset($_SESSION['hits'])) { $_SESSION['hits'] = 0; } $_SESSION['hits']++; echo 'You have vistited this site <strong>' . $_SESSION['hits'] . '</strong> times.'; ?>
if you load this page and then press F5, the session value will increase by each request so you see something like:
- You updated this site 1 time.
- You have updated this site 2 times.
- You have updated this site 3 times.
- You have verified this site 4 times.
- ...
The session file is unique for each person who visits, which means that when using the session variable in PHP it will be only for this user, so everyone gets their own session.
as you research its StackOverflow search products for specific tags such as PHP and sessions.
https://stackoverflow.com/questions/tagged/php+session
Here is a good question regarding the benefits of cookies and sessions, etc.
Assigning PHP Sessions and Cookies and Their Differences