Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 119405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:38:52+00:00 2026-05-11T03:38:52+00:00

<?php session_start(); include(connect.php); $timeout = 60 * 30; $fingerprint = md5($_SERVER[‘REMOTE_ADDR’] . $_SERVER[‘HTTP_USER_AGENT’]); if(isset($_POST[‘userName’]))

  • 0
<?php session_start();  include('connect.php');  $timeout = 60 * 30; $fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);  if(isset($_POST['userName'])) {     $user = mysql_real_escape_string($_POST['userName']);     $password = mysql_real_escape_string($_POST['password']);     $matchingUser = mysql_query('SELECT * FROM `users` WHERE username='$user' AND password=MD5('$password') LIMIT 1');     if (mysql_num_rows($matchingUser))     {         if($matchingUser['inactive'] == 1)//Checks if the inactive field of the user is set to one         {             $error = 'Your e-mail Id has not been verified. Check your mail to verify your e-mail Id. However you'll be logged in to site with less privileges.';             $_SESSION['inactive'] = true;         }         $_SESSION['user'] = $user;         $_SESSION['lastActive'] = time();         $_SESSION['fingerprint'] = $fingerprint;     }     else     {         $error = 'Invalid user id';     } } if ((isset($_SESSION['lastActive']) && $_SESSION['lastActive']<(time()-$timeout)) || (isset($_SESSION['fingerprint']) && $_SESSION['fingerprint']!=$fingerprint)      || isset($_GET['logout'])     ) {     setcookie(session_name(), '', time()-3600, '/');     session_destroy(); } else {     session_regenerate_id();      $_SESSION['lastActive'] = time();     $_SESSION['fingerprint'] = $fingerprint; } ?> 

This is just modified version of http://en.wikibooks.org/wiki/PHP_Programming/User_login_systems

What does the setcookie(session_name(), '', time()-3600, '/'); do here?

Here’s a bug: I use this login form:

<?php     if(!isset($_SESSION['user']))     {         if(isset($error)) echo $error;            echo '<form action='' . $_SERVER['PHP_SELF'] . '' method='post'>         <label>Username: </label>         <input type='text' name='userName' value='';if(isset($_POST['userName'])) echo $_POST['userName']; echo '' /><br />         <label>Password: </label>         <input type='password' name='password' />         <input type='submit' value='Login' class='button' />         <ul class='sidemenu'>         <li><a href='register.php'>Register</a></li>         <li><a href='forgotPassword.php'>Forgot Password</a></li>     </ul>     </form>';     }     else     {         echo '<ul class='sidemenu'>         <li>' . $_SESSION['user'] . '</li>         <li><a href='' . $_SERVER['PHP_SELF'] . '?logout=true'>Logout</a></li>         </ul>';     } ?> 

The bug is that when I logout, the page remains the same, i.e. the login form does not show up but the same logout and user are shown. When I refresh the page, it gets normal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:38:53+00:00Added an answer on May 11, 2026 at 3:38 am

    When you log out, first, you are queuing the destruction of the cookie (it will occur after the response is sent), then immediately after, rendering your page. The browser has no chance to delete the cookie before rendering, and your $_SESSION variables are still alive.

    PHP docs say about session_destroy:

    session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.

    A solution is to, instead of destroying the session and the cookie, simply unset the variables which would cause authentication:

    unset($_SESSION['user']); unset($_SESSION['lastActive']); unset($_SESSION['fingerprint']); 

    Just a note: I would suggest splitting your code up into functions. This would make it much more organized and readable (and reusable if you do things right).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If this is your first game application, using multi-threading to… May 11, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer Lo logré, I gotz it!! I now have a basic… May 11, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer Use the array union operator. $array3 = $array1 + $array2; May 11, 2026 at 6:23 pm

Related Questions

<?php session_start(); include(connect.php); $timeout = 60 * 30; $fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); if(isset($_POST['userName']))
I am creating a user login system similar to a client intranat. And when
Below is a page that handles a login script and I am wondering if
For some reason the login to my site has to be done two times
I am trying to build a site with news links that can be voted,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.