I am having problems with keeping a session active in the home directory of my website.
I have a file named login.php where the session is set. Then if I navigate to index.php and do print_R($_SESSION), it prints it. Then I go to gallery.php and it is gone. Same is true in reverse order: it appears if I go to gallery.php first, then disappears in index.php.
I’m thinking it might be the php.ini related.
edit:
Ok I figured out it was an included file that was causing this, its included on both pages, called ‘nav.php’
<?php
session_start();
$logout = intval($_GET['logout']);
if(isset($logout)){
session_destroy();
//header('Location: '$_SERVER['PHP_SELF']);
}
echo '<a href="/index.php" title ="home" class="navbutton">home</a>
<a href="/gallery.php" title ="gallery"class="navbutton">gallery</a>
<a href="/info.php"title ="info"class="navbutton">info</a>
<a href="/contact.php"title="contact"class="navbutton">contact</a>';
if(isset($_SESSION['names']) || isset($_SESSION['guestlogin'])){echo '<a href="'.$_SERVER['PHP_SELF'].'?logout=1" title="logout"class="navbutton">logout</a>';
echo'<a href="/gallery" title ="gallery"class="navbutton"> test gallery</a>';
}
else{echo '<a href="/login" title="login"class="navbutton">login</a>';
}
echo'<a href="/blog"title ="blog"class="navbutton">blog</a>
<a href="/prints"title ="prints"class="navbutton">prints</a>';?>
could it be b/c it has session_destroy in it or something? Also are all included files supposed to have a session_start on them?
Do you see a problem here?
$logoutalways has some value. No matter what the value is. Soisset($logout)is alwaysTRUE. Change it to:This will logout user if he followed URL with
logout=1in query string.