0

after login if i click logout (logout.php) its nor redirecting to login page. its stuck in logout.php page.

logout.php

<?php 
session_start();
session_destroy();
if(!$_SESSION['username']){
header("Location: login.php");
}
?>

index.php

<?php
include("config.php");
session_start();
$usern = $_SESSION['username']; 
//if(!isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) == '')) {
if(!$_SESSION['username']){
header("location:login.php");
} ?>


<div class="cssmenu">
            <ul>
<?php if($usern){ ?>
                     <li><a href="logout.php">Log Out</a></li> 
                    <?php }
                    else { ?>
                        <li><a href="login.php">Log In</a></li> |
                        <li><a href="register.html">Sign Up</a></li>
                    <?php } ?>
                    </ul>
                    </div>
3
Contributors
5
Replies
20
Views
3 Years
Discussion Span
Last Post by malatamil
0

no am not getting any error it shows empty page

Edited by malatamil: d

0

You don't need the if in your logout, as it's always true.

In login, remove lines 6-8. That is causing a redirect loop.

0

after removing that line 6-8 in index.php again am facing the same problem

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.