php (session control)

setcookie is used to set cookies:

Insert picture description here

setcookie can also delete the specified cookie.

Insert picture description here

Insert picture description here

Encrypt data through the md5 function.

Insert picture description here

This is a cookie found before login.

Insert picture description here

After successful login, it is found that setcookie takes effect locally. The cookie is stored, and the key value is encrypted using the md5 function.

Insert picture description here

The cookie value can be retrieved through the $_COOKIE array.

Insert picture description here

The session is generally stored on the server side.

The session must be opened before use, session_destroy will destroy the session so that it cannot be used in other files, and the session information is also stored in the corresponding $_SESSION array.

Insert picture description here

You can see the session information just stored.

Insert picture description here

Insert picture description here

Since the session_destroy function was called just now, the session information is not available on this page.

Insert picture description here

Comment out this function, and reload the session.php page, and then enter the session2.php page.

Insert picture description here

You can see that the session information stored in the session.php page is retrieved on the session2.php page

Insert picture description here

You can use the unset function to destroy a specified key value in the session.

Insert picture description here

You can see that the username key and the corresponding value have been destroyed.

Insert picture description here

Through cookie and session, user login and session control can be realized flexibly.

Guess you like

Origin blog.csdn.net/qq_46456049/article/details/108589470