Get the App
SLTechnology News&Howtos  ›  Development  › 

How php deletes session_id

Shulou Source: shulou.com Published: 2022-06-03 09:45:26 09月30日 Update

This article mainly introduces php how to delete session_id, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

In php, you can use the unset () function to delete "session_id", which destroys a given variable in the syntax format "unset ($_ SESSION ['session_id']);".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

To delete a session value, you can use the unset function of PHP. After deletion, it is removed from the global variable $_ SESSION and cannot be accessed.

Session_start (); $_ SESSION ['name'] =' jobs';unset ($_ SESSION ['name']); echo $_ SESSION [' name']; / / prompt that name does not exist

If you want to delete all session, you can use the session_destroy function to destroy the current session,session_destroy and delete all data, but the session_id still exists.

Session_start (); $_ SESSION ['name'] =' jobs';$_SESSION ['time'] = time (); session_destroy ()

It is worth noting that session_destroy does not immediately destroy the value in the global variable $_ SESSION, and $_ SESSION is empty only the next time it is visited, so if you need to destroy $_ SESSION immediately, you can use the unset function.

Session_start (); $_ SESSION ['name'] =' jobs';$_SESSION ['time'] = time (); unset ($_ SESSION); session_destroy (); var_dump ($_ SESSION); / / empty at this time

If you need to destroy the session_id in the cookie at the same time, which may be used when the user exits, you also need to explicitly call the setcookie method to delete the cookie value of the session_id.

Task

Use unset to delete the session value of name.

Tags: Functions articles variables global at the same time time values tasks interests only tutorials data methods more friends formats environment users computers knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Shulou Tech Info MariaDB Shulou Technology