0

I'm trying to override all logout situations (timeout-sessions, or simply any method that refers to [logout.php] page!) by specifying a single logout button in the index page. Is this possible? And what did I miss? Thanks in advance.

The code used in the [index.php]:

<?php
session_start();
if(isset($_POST['logout'])) {
    $_SESSION['logout_command'] = 1;
    header("Location: logout.php");
}
?>

<form action="" method="post">
    <input type="submit" name="logout" value="LOGOUT!!!">
</form>

And the code in the [logout.php]:

<?php
session_start();
if(isset($_SESSION['logout_command'])) {
    $check = $_SESSION['logout_command'];
    if($check = 1) { // AND ONLY IF!
        session_destroy();
        header("Location: login.php");
    } else { // BACK OFF!
        header("Location: index.php");
    }
} else { // ALSO BACK OFF!
    $_SESSION['logout_command'] = 0;
    header("Location: index.php");
}
?>

UPDATE: So, I missed the comparing (==) signs... Also, the [exit()] function after each [header()] in a sequence... Thanks to everyone.

  • 1
    After every `header('Location: /example.php');` you need to use the `exit();` method. – Jaquarh Sep 04 '17 at 17:00
  • @Qirel It wasn't my purpose to be honest... I'm just concerned about restricting the logout process... –  Sep 04 '17 at 17:10
  • 1
    @Sky7ure It's alright if your question is flagged as a duplicate - its just that we gather frequently asked questions/issues into single threads with a deeper explanation, so they become more useful and easier to use for a larger userbase. – Qirel Sep 04 '17 at 17:14

1 Answers1

2

You're not doing a conditional, you're assigning the value in your first if:

if($check == 1) {
ishegg
  • 9,685
  • 3
  • 16
  • 31