943,832 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 994
  • PHP RSS
Jul 15th, 2009
0

Users have to login and logout twice, why?

Expand Post »
Hi..
I'm newbie here..

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

Here is the login script:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $q = "SELECT * FROM members WHERE username='%s' AND password='%s'";
  3. $q = sprintf($q, $username, $password);
  4. $q = mysql_query($q);
  5. if (mysql_num_rows($q) > 0) {
  6. $_SESSION['id'] = $q[0]['id'];
  7. $IS_LOGGED_IN = true;
  8. }
  9. ?>

here is the logout script:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. unset($_SESSION['userid']);
  4. session_destroy();
  5. $_SESSION = array();
  6. header('Location: index.php');
  7. ?>

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..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
eantz is offline Offline
29 posts
since Jul 2009
Aug 18th, 2009
0

Re: Users have to login and logout twice, why?

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
No Box is offline Offline
1 posts
since Aug 2009
Aug 19th, 2009
0

Re: Users have to login and logout twice, why?

Yes, Check all the links and conditions on your web page. may be some where else same working is happening.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Simple PHP Regex Question!
Next Thread in PHP Forum Timeline: PHP variable in link





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC