phpmysqlauthentication

how to use login script for each page in php and mysql


i have used the login script which is found here http://www.phpeasystep.com/phptu/6.html the script works fine and i finally reach the login success page after entering the correct details.

but i need help with how do i use this for all the pages on my website. what is the header that i should be mentioning on each page that i want to be password protected and also that the user does not have to login multiple times within the website and the session to be reset in a particular period that i am able to mention

i know it might sound dumb but sorry i am a novice and don't know programming.


Solution

  • your going to want to have a cookie/session set when the user logs in, and then have each page check to see if that session/cookie is set, and if it's not redirect them to the login page.

    here is a little example on how to set the session:

    <?php
    session_start();
    $_SESSION['auth'] = "OKAY";
    ?>
    

    and here is a little snippit for each page to check for the session:

    <?php
    session_start();
    if(!isset($_SESSION['auth']))
    {
    header("Location: your_login_page.php");
    }
    //display page here
    ?>
    

    mind you this is a very basic example.

    hope that helps!