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

  • SEARCH
  • Home
  • 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 8213015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:58:13+00:00 2026-06-07T10:58:13+00:00

Really annoying problem I can’t solve/can only partially solve. Nice juicy one for you

  • 0

Really annoying problem I can’t solve/can only partially solve. Nice juicy one for you pros.

I’ve got a basic login system set up. Like this:

Login.php:

  1. line 1: session_start();
  2. Check if($_SESSION['logged_in'] == true) header("Location: /controls.php);, incase they’ve already entered their details.
  3. If they haven’t entered them yet, user enters credentials, if valid: $_SESSION['logged_in'] = true;
  4. After database credentials are checked and session is set to true, redirect using PHP header("Location: /controls.php);

Bear in mind, the session is now set.

Controls.php

  1. line 1: session_start();
  2. line 2: if($_SESSION['logged_in'] != true) {header("Location: /index.php");}

Instantly I get taken to index.php ONLY IN CHROME AND FIREFOX.

Also, I have accounttools.php, where the session is again required. Once I try to access accounttools.php, the session is destroyed/unset and any attempt to load accounttools.php results in the header redirect to my /index.php page, again ONLY IN FIREFOX AND CHROME.

I’ve also got to add in something. If I go back to login.php and re-login, everything works fine and the session gets set properly. Is this a browser-based bug? PHP is executed before any data gets sent to the browser, so how on earth can these browsers act differently if the PHP has already been executed by the time anything reaches the user?

Login file:

// Login.php
<?php session_start();

if($_SESSION['logged_in'] == true)
{
    header("Location: /controls.php");
    exit();
}

if($_POST['username_login'] && $_POST['password_login'])
{
    // Do necessary database work to check credentials (edited out here).
    // ...    
    // Check re-hashed pass against database hash (password checking)
    if($make_password == $current_user[0]['password'])
    {
        // If this is OK login is a success.
        $_SESSION['logged_in'] = true;
        header("Location: /controls.php");
        exit();
    }
}
?>

Controls file:

// controls.php
// This page instantly redirects to index.php
<?php session_start();

// Go to homepage if logging out.
if($_POST['logging_out']) 
{
    unset($_SESSION['logged_in']); 
    header("Location: /index.php"); 
    exit();
} 
// No access unless logged in.
// This session seems to no longer exist at this point. Why??
if($_SESSION['logged_in'] != true)
{
    header("Location: /index.php");
    exit();
}
?>

Edit: I’ve discovered something else: If I login and manually enter the URL of the $_SESSION-restricted page, the $_SESSION is not destroyed.

There is some part of the header() redirect that is causing th $_SESSION to become unset/destroyed in Google and Mozilla.

I’ve also been Googling like crazy and apparently this is a common problem amongs PHP coders. Someone must have a clue what this is?

  • 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. Editorial Team
    Editorial Team
    2026-06-07T10:58:16+00:00Added an answer on June 7, 2026 at 10:58 am

    I see a problem with the way you are redirecting after a successful login: It is a javascript redirect so it will only happen after all the php has finished executing and the result has been sent to the browser. That means that codes after your redirect are executed as well.

    I would recommend not outputting anything to the browser until the very end and use the:

    header("Location: /...");
    exit();
    

    combination everywhere where you want to redirect so that you are sure that nothing happens to your session after the redirect code.

    To avoid getting headers already sent problems, I would also recommend getting rid of stuff like:

    ?>
    <?php
    

    like on the first lines of login.php.

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

Sidebar

Related Questions

I've got a really annoying problem, and as much as I've searched, I can't
I've got a really annoying problem: I'm working on a collaborative text editor in
I've got an annoying problem here. I've recently upgraded to VS 2010. I really
I have a really annoying problem that I tried to solve for a few
I have a really annoying problem. I got this bunch of code which runs
I'm working with Qt Creator 2.4.1 and I faced with one really annoying problem.
I am having this really annoying problem on a php-site I am programming and
I've run into a really annoying problem, and I'm hoping it's just a setting
I'm dealing with an annoying database where one field contains what really should be
I just ran into an annoying problem. Suddenly Avira AntiVir started to flag one

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.