My php login code working properly in my local machine, but its give blank page in login-post.php on server side.
I am working almost a week on this issue. Now i post question here. Some points that i already tried:
1- already use try and catch black in my code
2- I have no .htaccess file on my server, so no issue in it.
3- Give 777 permission to all files first i use ajax call, then convert it to form submission.
4- echo after each line, so that i can identify the error place, but not a single line echo. Even my first echo is at the start of file.
5- No database issue because application sign-up is working proper, though that sign-up is similar with login functionality.
Note : This code is working properly for my local server, but not working in server side.
My code is :
<?php
session_start();
$message = '';
try{
$userName = trim($_POST['username']);
$password = trim($_POST['password']);
if (empty($userName) || empty($password)) {
$message = "<p class='error'>Required Parameter is missing</p>";
} else {
include "database_access.php";
if (!$connection) {
$message = "<p class='error'>Connection Failed.</p>";
} else {
$stmt = $connection->prepare('SELECT name, username FROM users WHERE username = :username AND password = :password');
$stmt->execute(['username' => $userName, 'password' => hash('sha512', $password)]);
$user = $stmt->fetch();
if (empty($user)) {
$message = "<p class='error'>User Name or Password is incorrect</p>";
} else {
$_SESSION['logged_in'] = $userName;
header('Location: welcome.php');
exit();
}
}
}
}catch (Exception $e) {
$message = "<p class='error'>Error : " . $e->getMessage() . "</p>";
}
$_SESSION['login-error'] = $message;
header('Location: login-get.php')
?>
and login-get.php form tag is here:
<form id="login-form" method="post" action="login-post.php" class="form-horizontal form-login">
</form>