Question:

Php. Check to make sure user is till logged in. Help... cookie??

by  |  earlier

0 LIKES UnLike

OK, so here is what i did.

1. index.php

so on this page you type in your information into the username and password slots and when you click submit it sends your info to login_check.php. ($_POST['username'] etc.]

2. login_check.php

once here it checks the database to see if you are actually registered. if you are it sends you to members_home.php. if you are not logged in it sends you to index.php.

Here is where im stuck. what code do i put at the top of members_home.php to make sure whoever is viewing this page is logged on. I think its a cookie im supposed to do. How would i do this?

 Tags:

   Report

1 ANSWERS


  1. hi,

    heres a HINT, on your login_check.php you should set a cookie where you will store the USERNAME, a good example would be

    $user = $_POST['username'];

    set_cookie("username", $user , time( ) + 3600);

    // cookie username will expire in 1hour(3600 milliseconds)

    THEN, on your members_home.php you should check wether $_COOKIE['username'] is SET. A sample code would be

    if( isset( $_COOKIE['username'] ) )

    {

    // do nothing

    }

    else // if not set redirect to index.php

    {

      header("Location: index.php");

    }

    hope this helps.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.