I am trying to write a simple login code. The problem is that the code works and redirects to dashboard.php without any css and js files. But as soon as include my header file,consisting of css and js, it stops working and gets stuck on auth_check.php. Here is my code.
main index file ( index.php) - containing the login form
<?php include('header.php');?>
<?php
$message = $_GET['message'];
if($message == 1) {
echo '
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
Invalid username or password.</br> ×</button>
</div>
';
}
if($message == 2) {
echo '
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">
You have successfully logged out! </br> ×</button>
</div>
';
}
?>
<div data-role="content">
<div id="loginform" > //Login form code
<form action="auth_check.php" method="post"> // form action="auth_check.php"
<div id="usernameDiv" data-role="field-contain">
<input type="text" id="name" name="username" placeholder="Username">
</div>
<div id="passwordDiv" data-role="field-contain">
<input type="password" id="password" name="password" placeholder="Password">
</div>
<div id="loginbuttonDiv" data-role="field-contain">
<button type="submit" name="submit" id="loginbutton"></button>
</div>
</form>
</div>
<?php include('footer.php'); ?>
Authorisation check (auth_check.php) (here the header(location:) doesnt work after applying js in index.php :(
<?php
include('config.php');
session_start();
include 'PasswordHash.php';
$hasher = new PasswordHash(8, FALSE);
if (!empty($_POST))
{
$username = $sql->real_escape_string($_POST['username']);
$query = "SELECT id, password, UNIX_TIMESTAMP(created) AS salt
FROM users
WHERE username = '{$username}'";
$user = $sql->query($query)->fetch_object();
if ($user && $user->password == $hasher->CheckPassword($_POST['password'],
$user->password))
{
session_register("username"); // session checker for pages
$_SESSION['username']= $username; // storing username in session
header("location: dashboard.php");
exit;
}
else
{
header("location: index.php?message=1");
exit;
}
}
?>
here is the file header.php which is causing the problem.
<?php
include('config.php');
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" type="text/css" href="custom.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-
1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript" src="js/login.js"></script>
<head>