Jump to content

Header


N-Bomb(Nerd)

Recommended Posts

Hi,

 

I'm using a config.php file at the top of all my php files for my project. In my config.php I have the following at the very top:

 

session_start();

if(!$_SESSION['loggedIn'])
{

    header('Location: login.php');
    //echo 'redirect to login.php';

}

 

So, I go to any other file in my browser that has config.php included and I get the following message from firefox:

The page isn't redirecting properly

 

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

   

    *  This problem can sometimes be caused by disabling or refusing to accept

          cookies.

 

I check the cookies in my firefox and I see the cookie there and I also look in my tmp session folder and I see it there as well.. what am I doing wrong?

 

Simply want to redirect any user that isn't logged in to the login page.

 

--

 

Also, in the above code I also have an echo line that's commented out -- if I comment out the header and use the echo line it echos in all the places I need the header to work.

 

There's nothing outputted before the header or anything..

Link to comment
https://forums.phpfreaks.com/topic/203339-header/
Share on other sites

Logically it sounds like $_SESSION['loggedIn'] is not set, and the same check is being performed on the login.php page. So when it hits that page it is endlessly redirecting back to itself. That is the only time I have seen that in my personal experience.

 

That makes sense.. God, why didn't I think of that? :D

 

I wanted to keep the authentication pretty simple and use the config.php to make sure the user is logged in. However, I need to use the config.php on my login page... how should I go about this?

Link to comment
https://forums.phpfreaks.com/topic/203339-header/#findComment-1065313
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.