Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize logout and clear session by php

Shulou Source: shulou.com Published: 2022-06-03 13:18:10 11月14日 Update

This article mainly introduces php how to log out to clear session, the article is very detailed, has a certain reference value, interested friends must read it!

Php login clear session implementation methods: 1, clear the session value; 2, determine whether the client's cookie file exists, then set it to expire; 3, clear the server's sesion file.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer

How does php log out to clear session?

PHP most thoroughly log out, clear the code of session and cookie

Public function logout () {$_ SESSION = array (); / / clear session value. If (isset ($_ Cookie [session _ name ()]) {/ / determines whether the client's cookie file exists, and sets it to expire if it exists. Setcookie (session_name (),', time ()-1);} session_destroy (); / / clear the server's sesion file}

When logging out, if the session or cookie is not cleaned clean, it will often cause all kinds of fantasy problems. Especially if your session is stored in a database driver on the server. Use the above code to clean it up thoroughly.

The above is all the contents of the article "how to log out and login to clear session" in php. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Login file server service clean code content client end article value interest buddy partner data database method time more environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker MariaDB Xiaomi Huawei