Saturday, 28 September 2013

Not redirecting on successfull login

Not redirecting on successfull login

I have compleated a login form and works 100% on my WAMP server however
when I run it on a live server everything works 100% apart from when i log
in it does not redirect my page to the page it should (just displays a
blank HTML page). It is however logged in because if I enter the url of
the page it sould go it displayes like it should. The path to the file is
correct. I hope my problem is clear. Here is the code for my login form:
<?php include_once "includes/scripts.php"; ?>
<?php
session_start();
include_once ("includes/connect.php");
if (isset($_SESSION['logged_in'])) {
header('location: admin_cms.php');
exit();
}else{
if (isset($_POST['username'], $_POST['password'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
if (empty($username) or empty($password)){
$error = '<p>NOTE: Fields are blank</p>';
}else{
$query = $pdo->prepare("SELECT * FROM users WHERE user_name =
? AND user_password =?");
$query->bindValue(1, $username);
$query->bindValue(2, $password);
$query->execute();
$num = $query->rowCount();
if ($num == 1){
$_SESSION['logged_in'] = true;
header('location: admin_cms.php');
exit();
}else{
$error = "<p>NOTE: The username or password is
incorrect</p>";
}
}
}
?>
<div id="login_container">
<br><img src="images/camelhorst_logo_full.png"
style="margin-top:38px;">
<h1>LOGIN<img src="images/three_column_grid_line.png"
alt="line"></h1>
<form acton = "admin.php" method="post" autocompleate="off">
<label>Username:</label>
<input type="text" name="username" placeholder="Your Username"
required autocomplete="off">
<label>Password:</label>
<input type="password" name="password" placeholder="Your
Password" required autocomplete="off">
<input type="submit" value="Login" name="submit_login">
</form>
<?php if (isset($error))
{echo $error;}?>
<p id="copyright_admin"> © CAMELHORSE CREATIVE STUDIO 2013 </p>
</div><!--login_container-->
<?php } ?>
</body>
</html>
I am sorry if it is a noob question or i am overlooking something simple
but i am very new to PHP

No comments:

Post a Comment