Clicking one of the links will lead you to a new index, but you would only be able to view the index if you are already logged in.
I tried to check that by using this code:
(i put this code on top of the index file's code)
Expand|Select|Wrap|Line Numbers
- <?
- //check that the user is calling the page from the login form and not accessing it directly
- //and redirect back to the login form if necessary
- if (!isset($username) || !isset($password)) {
- header( "Location: login.php" );
- }
- //check that the form fields are not empty, and redirect back to the login page if they are
- elseif (empty($username) || empty($password)) {
- header( "Location: login.php" );
- }
- else{
- ?>
How do I make this work properly so that the site cannot be viewed directly unless already logged in and stored in a session.
My session code is:
Expand|Select|Wrap|Line Numbers
- <?php
- // start the session
- session_start();
- //if the session is registered to a valid user then show content
- if (session_is_registered("$username")) {
- echo "Access granted.";
- }
- //not registered session
- else {
- header( "Location: login.php" );
- }
- ?>
=(
Thank you for answers