0

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>
  • Have you tried `error_reporting(E_ALL)`? – michip96 May 29 '17 at 09:47
  • post your full html form. including inputs – Rotimi May 29 '17 at 09:49
  • no i don't use it. how to do this? – Amina Nisar May 29 '17 at 09:49
  • Hi Amina, probably your login form doesn't work because there is some misconfiguration in your production server (Wrong DB conf, files/modules missing, etc). First you have to activate temporally the error display/log in your production server in order see what is going. See https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Juan Lago May 29 '17 at 09:50
  • i tried this but no issue reported @JuanLago – Amina Nisar May 29 '17 at 10:05
  • i use echo at first line of this page and exit as well, but still blank page show. @michip96 I don't know thats wrong with this code on server side, but in my local side its working perfectly fine – Amina Nisar May 29 '17 at 10:07
  • Amina, I forgot to tell you that after change the PHP configuration you have to restart the webserver. If you don't know how to restart the webserver, just reboot the server. – Juan Lago May 29 '17 at 12:31

0 Answers0