Basicly we're at a navigation page with a lot of different links.
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)
It doesnt work at all and I go straight to index, instead of redirecting us to the login.php.
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:
Which doesn't seem to be working either..
=(
Thank you for answers
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)
Code:
<?
//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:
Code:
<?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
Comment