I am creating a login system, my login and register script is working fine but when i started with page permission it did not work, it keeps on redirecting to the landing page
index.php
<?php
include_once("scripts/global.php");
if( $logged == 1 ){
header("Location:home.php");
exit();
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Webplex</title>
<link href="style1.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container center">
<h1>Webplex</h1>
<a href="register.php"><p>Register</p></a> | <a href="login.php"><p>Login</p> </a>
</div>
</body>
</html>
global.php
<?php
session_start();
include("scripts/connect.php");
//check the session
if(isset($_SESSION['username'])){
$session_username = $_SESSION['username'];
$session_pass = $_SESSION['pass'];
$session_id = $_SESSION['id'];
//check member
$query = mysql_query("SELECT*FROM members WHERE `id` = '$session_id' AND `password` = '$session_pass' LIMIT 1") or die("could not perform");
$count_count = mysql_num_rows($query);
if($count_count > 0){
//logged in stuff here
$logged = 1;
}else{
$logged = 0;
header("Location:logout.php");
exit();
}
}else if(isset($_COOKIE['id_cookie'])){
$session_id = $_COOKIE['id_cookie'];
$session_pass = $_COOKIE['pass_cookie'];
//check member
$query = mysql_query("SELECT*FROM members WHERE `id` = '$session_id AND `password` = '$session_pass' LIMIT 1")or die("could not perform");
$count_count = mysql_num_rows($query);
if($count_count > 0){
while($row= mysql_fetch_array($query)){
$session_username = $row['username'];
}
//create sessions
$_SESSION['username'] = $session_username;
$_SESSION['id'] = $session_id;
$_SESSION['pass'] = $session_pass;
//logged in stuff here
$logged = 1;
}else{
header("Location:logout.php");
exit();
}
}else{
//not logged in
$logged = 0;
}
?>
home.php
<?php
include_once("scripts/global.php");
if( $logged == 0 ){
header("Location:index.php");
exit();
}
?>
I am being redirected as soon as I login,