ALQAM ALQAM - 11 months ago 63
PHP Question

How to unset $_SESSION variable?

Good morning guys, I have set this code and i would like to unset $_SESSION["username"], IF $_POST["logout"] isset

<?php


if (isset($_POST["name"]) && isset($_POST["password"]))
$_SESSION["username"]=$_POST["name"];
unset($_SESSION["username"]);

if(isset($_POST["logout"]))
unset($_SESSION["username"]);

?>

Answer Source

It seem some bad logic in code, try

if (isset($_POST["name"]) && isset($_POST["password"])) {
    $_SESSION["username"]=$_POST["name"];        
}

if(isset($_POST["logout"])) {
    unset($_SESSION["username"]);
} 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download