I have been testing the login form page with the rightful credentials and the page loads perfectly by verifying credentials and prompts me to access the details,on my local server system.
However,I have deployed it on the remote server but whenever I login with the right credentials,the page spins and redirects back on the same page,What could this mean I didn't test my system on both remote server and local system at the once.
This the login page /index.php form;
<?php
session_start();
include('includes/config.php');
if(isset($_POST['adlogin']))
{
$uname=$_POST['username'];
$password=$_POST['password'];
$sql ="SELECT UserName,Password FROM admin WHERE UserName=:uname and Password=:password";
$query= $dbh -> prepare($sql);
$query-> bindParam(':uname', $uname, PDO::PARAM_STR);
$query-> bindParam(':password', $password, PDO::PARAM_STR);
$query-> execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
$_SESSION['alogin']=$_POST['username'];
echo "<script type='text/javascript'> document.location = 'dashboard.php'; </script>";
} else{
echo "<script>alert('Invalid Admin Login Details');</script>";
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div class="main-wthree">
<div class="container">
<div class="sin-w3-agile">
<h2>Admin</h2>
<form method="post">
<div class="username">
<span class="username text-center">Username</span>
<input type="text" name="username" class="name" placeholder="" required="">
<div class="clearfix"></div>
</div>
<div class="password-agileits">
<span class="username text-center">Password</span>
<input type="password" name="password" class="password" placeholder="" required="">
<div class="clearfix"></div>
</div>
<div class="login-w3">
<input type="submit" class="login" name="adlogin" value="LogIn">
</div>
<div class="clearfix"></div>
</form>
</div>
</div>
</div>
<?php include('includes/footer.php');?>
</body>
</html>
<?php
define('DB_HOST','localhost');
define('DB_USER','database_username');
define('DB_PASS','database_password');
define('DB_NAME','database_name');
try
{
$dbh = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER, DB_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
}
catch (PDOException $e)
{
exit("Error: " . $e->getMessage());
}
?>
The dashboard file;
<?php
session_start();
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
{
header('location:dashboard.php');
}
else{
?>
<!DOCTYPE HTML>
<html>
<head>.......
What I have tried:
I tried to add
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
to the try block after the new PDO(...)
But still facing the same issue,the login file redirects back,I can't access the dashboard file still.This works on my local host tests but on remote server.