What is the PHP function session_start and session_destroy

PHP / MySQL - Sessions - Killing a session

1. The sections

2. Basics

Creating a session is Pipifax, as you now know. But not flattening them. First of all, a simple basic rule. Before you send them to the eternal hunting grounds, you have to use it beforehand, of course, otherwise you won't have access to them. Even when shooting away.

3. For God's sake

First of all, something very important! You must in no way, never, never, never do this.

unset ($ _ SESSION);

Because with this you deactivate the registration of variables by the superglobal.

4. Now it's getting difficult

There is a function to destroy a session. To just remove their contents, one uses.

But!

It doesn't always work 100 percent. Please don't ask me why. I do not know myself. Honestly, I've never even bothered about it.

5. Kill, destroy, destroy

If you want to definitely promote a session to the Orkus, you have to resort to a rather radical method.

<?php  session_start()  ...  session_unset();  session_destroy();    $_SESSION = array();?>

Explanation

As I said, only deletes the content. The session itself remains. By now the same is flattened. But since that is not always enough, you should also clean up. This has nothing to do with the sessions themselves, you just empty the superglobal array.

One more point

Both the session file and the session cookie still exist. Have a look on your server in the appropriate folder and in the settings of your browser. However, the connection between the two was "severed". Since a session cookie should only be valid for one session anyway, the thing is anyway after closing the browser.

back to the previous section to the next section

Info

Last change in content

11.04.2014

Data

Sample code

Just learn to program!

Easy to understand programming books for all programming languages!

Implement your own loT projects!

Your expert for Arduino, Raspberry Pi and microelectronics!

job advertisements

More job offers