I really don’t know much in php so my friend helped me to make login page.
However I end up into redirect loop if login information is correct.
Here’s my code:
index.php – Page
<?php
if (!$_SESSION['ajslkajslkgjals'])
header('Location: login.php');
?>
login.php – Page
<?php
session_start();
require_once('config.php');
$query = "SELECT * FROM admins";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();
$i = 0;
while ($i < $num) {
$admin_user = mysql_result($result, $i, "admin_username");
$admin_pass = mysql_result($result, $i, "admin_password");
$i++;
}
if(isset($_POST['login-form'])) {
$admin_username = $_POST['username'];
$admin_password = $_POST['password'];
if($admin_username==$admin_user && $admin_password==$admin_pass) {
$_SESSION['ajslkajslkgjals'] = $admin_user;
header('Location: index.php');
exit();
} else {
$status = "<script>
$.ajax({
url: '/',
data: {action: 'test'},
type: 'post',
success: function() {
notifyBox();
}
});
</script>";
}
}
if(isset($_SESSION['ajslkajslkgjals'])) {
header('Location: index.php');
exit();
}
?>
I will appreciate if anyone could give me some tips of where I made mistake ?
I just don’t get it! Thank you.
At the end of login.php you have a redirect to index.php. In index you don’t start the session so that if always executes the redirect.