I am creating a user login system similar to a client intranat. And when I try to access the main page I get a redirect loop in FF.
I am checking to see if a user is logged in with this:
if(($_SERVER['PHP_SELF'] != '/webmaster/index.php') && ($_SESSION['loggedin'] != '1234')){
header("Location: ".$domain."index.php?l=no");
exit();
}
Below is my process-login.php -> which is the file that handles client login:
<?php
ob_start();
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL | E_NOTICE);
include ("config.inc.php");
include ("jsonEncode.php");
// username and password sent from form
$username = '';
$password = '';
$username = mysql_real_escape_string($_GET['username']);
$password = mysql_real_escape_string($_GET['password']);
$sql = "SELECT * FROM clients WHERE username='$username' AND password='$password' LIMIT 1";
//echo $sql;
$result = mysql_query($sql);
$data = mysql_fetch_array($result);
$count = mysql_num_rows($result);
if($count==1){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['client_id'] = $data['c_id'];
$_SESSION['loggedin'] = "1234";
/*
echo $_SESSION['client_id'];
echo $_SESSION['password'];
echo $_SESSION['username'];
*/
echo $_SESSION['loggedin'];
// valid
$var = array('valid' => 1, 'username' => $username, 'password' => $password);
print php_json_encode($var);
}else{
// invalid
$var = array('valid' => 0, 'username' => $username, 'password' => $password);
print php_json_encode($var);
}
?>
The main index.php page has two forms one for clients and one for webmastsers, and if you are a client you are redirected too: clients/ and if you're a webmaster you're redirected too: webmaster/
I have checked my login scripts and it is returning the right information and logging it in, but it keeps looping.
Any ideas on what I can check or any other details I can provide you.
The form is submitted via ajax then returns JSON with a value of 1 being valid or 0 invalid to see if the user can continue
Thanks,
Ryan