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>

Recommended Answers

All 5 Replies

Do you get any message?? like an error??

no am not getting any error it shows empty page

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.

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

now its working. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.