Ghost
Ghost

Reputation: 13

logging out user with logout button will not redirect keeps going to php file instead of index

so im trying to log my user out and return them to the home screen but im just getting redirected to my logout.php file (white screen) any help here is the code:

(logout.php file)

<?php
session_Start();

unset($_SESSION['user_id']);
header("location../index.php");

?>

Button:

<li class="nav-item">
                        <?php if(isset($_SESSION['user_id'])): ?>
                        <a href="logout.php" class="nav-link btn-success logout-btn">Logout</a>
                        <?php endif; ?>
                    </li>

tried a bunch of different things and nothings working i expect to be redirected to the index.php login screen

Upvotes: 1

Views: 154

Answers (1)

David
David

Reputation: 218867

Because the location header is malformed, so the browser won't follow it. Try:

header("Location: ../index.php");

Upvotes: 1

Related Questions