Hi..
I'm newbie here..

I have a problem with my login and logout script..

Here is the login script:

<?php
$q = "SELECT * FROM members WHERE username='%s' AND password='%s'";
$q = sprintf($q, $username, $password);
$q = mysql_query($q);
if (mysql_num_rows($q) > 0) {
$_SESSION['id'] = $q[0]['id'];
$IS_LOGGED_IN = true;
}
?>

here is the logout script:

<?php
session_start();
unset($_SESSION['userid']);
session_destroy();
$_SESSION = array();
header('Location: index.php');
?>

and I have a variable which is called in every page that define some one logged in: $IS_LOGGED_IN = (isset($_SESSION['userid'] && $_SESSION['userid'] !== ''); With that code, users have to login twice before he is in real login state. It happens to with logout.

Why?

Thank's for helping me..

Check all of your links to the other web pages. I had the same problem with the session resetting itself when I had the <a href="http://www.yoursite.com/page.php"> instead of <a href="page.php"> I set all of them the same way no mixing and matching them together to navigate through the page and it worked.

Yes, Check all the links and conditions on your web page. may be some where else same working is happening.

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.