I am trying to make a user login site, I have a header.php and a home.php documents. I have the following code on the header.php page:
<?php
include ("./inc/connect.inc.php");
session_start();
if (isset($_SESSION['user_login'])) {
}
else
{
header("location: home.php");
}
?>
on the home.php page i have:
<?php
include("inc/header.inc.php");
?>
<?
if (!isset($_SESSION["user_login"])
?>
No matter what i try I am getting this loop error, please help :(
Always use exit();
after header("location: ..");
or it might not work as expected.
About Loop Error its possible both header.php
and home.php
are redirecting to each other.
I am not sure if its the same file (correct me if am wrong)
In header.php
you are redirecting user to home.php
if session is not set AND in home.php
you are including a file header.inc.php
(i am assuming its the same file) which is redirecting user to home.php
again and again
There is nothing that sets $_SESSION['user_login']
in those two files, you need to set this parameter in header.php
otherwise it will keep falling into this condition:
else
{
header("location: home.php");
}
The loop is as follows:
home.php
header.php
is includedheader.php
checks to see if $_SESSION['user_login']
has been sethome.php
I'm not entirely sure what you want to achieve here, but I'm going to assuming you want to display a page, but if the user isn't logged in to display something else?
Why not:
if (isset($_SESSION['user_login']) {
include('logged_in.php');
} else {
include('login_page.php');
}
Rather than bounce the user around, just display a different file?