Hello,

I am coding a login authentication system.
All php pages in the website continually check that the user is logged in, using this algorithm:

Is user logged in?
true
{
do what supposed to do
}
false
{
load contents of invalidpassword.php
}

So if the user is not logged in, any webpage called must show a common page called invalidpassword.php. Since a login failure causes NOTHING to be output except for the invalidpassword.php page, I can either load this page up from within the current page and output the contents, or redirect the current page to it.

What is the best way of outputing invalidpassword.php from within another file? Bearing in mind, it only needs to contain html and no PHP instructions.

Thanks in advance,
James.

    I would think the best solution is simply this:


    if ( userIsNotLoggedIn() ) {
    header( "Location: invalidpassword.php" );
    }

    // Main page code here.

    If the user is not logged in then a redirect will be done to the invalidpassword.php page. If the user is logged in then the rest of the page code is displayed.

    D

      use "include('invalidpassword.php');" if you don't want to send a new location header.

      It would probably be easier to use the header method that Don mentioned though. Then you could just include a single call to a function at the top of every page you wanted to verify login status on rather than dealing with a control structure on every page.

        Write a Reply...