Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Redirect if not logged in

  • 15-04-2015 7:10pm
    #1
    Registered Users, Registered Users 2 Posts: 3,097 ✭✭✭


    Hi all,

    I'm am developing an PHP, SQL website at the moment involving a basic login and signup page for college. What I have working is the sign up and login but I somehow need to add in if the user is not logged in her or she cannot access certain pages.

    I think I need to implement a cookie as far as I know I am not to sure now.


Comments

  • Registered Users, Registered Users 2 Posts: 2,032 ✭✭✭colm_c


    You need to look at sessions.

    Basic theory is you store the user's info/status (or a reference to it) in a session.

    Then you can check the session's contents/variable to see if they are logged in.

    PHP has session management built in have a look at $_SESSION.

    Under the hood PHP will set a cookie to a session reference and you're just writing to this session.

    You don't want to store info directly in a cookie especially logon information as it can be seen in the clear, but sessions it only stores a reference to the session and the data is retained on the server.


  • Registered Users, Registered Users 2 Posts: 1,595 ✭✭✭Gaz


    Just expanding on the above, what I do is include a check.php on every page I want protected.

    Set the session variable when the user logs in, then each page checks for this in the check.php. Like this ...

    if(!isset($_SESSION) || (trim($_SESSION) == '')) {
    header("location: logon");
    exit();
    }

    Oh and dont forget to start the sessions on each page with session_start();


Advertisement