0

My headers are not working at all now and no response is been shown
My php file looks like this

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
ob_start();
session_start();
require('../in/connect.php');
require ('../password.php');
if (isset($_POST['signup'])) {
  $username = stripslashes($_POST['user']);
  $username = mysqli_real_escape_string($con,$username);
  $username = str_replace(" ", "_",$username);
  $password = stripslashes($_POST['pass']);
  $password = mysqli_real_escape_string($con,$password);
  $email = stripslashes($_POST['email']);
  $email = mysqli_real_escape_string($con,$email);
  $date = $_POST['date'];
  if (($date != '') && ($email != '') && ($password != '') && ($username != '')) {
  $passwordnew = (password_hash($password, PASSWORD_DEFAULT));
  $trn_date = date("Y-m-d H:i:s");
  $query = "INSERT into `users` (username, email, password, trn_date, birth_date)
         VALUES ('".$username."', '".$email."', '$passwordnew', '$trn_date','$date')";
        $result = mysqli_query($con,$query);
          if ($result){
            $sql = mysqli_query($con,"SELECT * FROM `users` where username = '".$username."'");
            $user = $sql->fetch_assoc();
        $id = $user['id'];
        $_SESSION['username'] = $user['username'];
        $_SESSION['id'] = $id;
        $_SESSION['password'] = $password;
        header("location:./");
        }
}
}
?>

The entry I been made and the session variables too but no redirect and no error in the logs.
Already checked this thread How to fix "Headers already sent" error in PHP

j.edgar
  • 13
  • 7
  • 2
    Are you actually flushing the output buffer? I'm not seeing `ob_flush()` ... – CD001 Jun 29 '18 at 13:26
  • check the error_log are you on local or on a domain? – Avi Teller Jun 29 '18 at 13:26
  • Its,empty @AviTeller – j.edgar Jun 29 '18 at 13:27
  • follow what CD001 said – Sugumar Venkatesan Jun 29 '18 at 13:31
  • 1. You have an sql injection problem, you should use prepared statements, 2. You should never store the users password in the session, 3. Have you tried redirecting to a complete url? 4. Why are you manipulating the users password? – jeroen Jun 29 '18 at 13:32
  • I don't think I have a sql injection problem. tell me where it is @jeroen – j.edgar Jun 29 '18 at 13:34
  • 2
    `$date` is not safe. – IncredibleHat Jun 29 '18 at 13:35
  • its a input type date . I'll see to it anyways @IncredibleHat – j.edgar Jun 29 '18 at 13:36
  • 1
    `$date = $_POST['date'];` ... anyone can pass anything in on that :( So its better to safegaurd it. But all of this could be done easier with prepares (but thats outside the topic... since this is about your ob_start). – IncredibleHat Jun 29 '18 at 13:37
  • removed `OB_start` still nothing – j.edgar Jun 29 '18 at 13:40
  • instead of header redirect please use javascript redirect like below echo '' might be header redirect not working beucase included file content echo statement. – Evince Development Jun 29 '18 at 13:41
  • Using `ob_start()` is fine to avoid sending the headers in case of output that would cause your `header()` call to fail. You should probably turn it off during development, but that is not the problem here. – jeroen Jun 29 '18 at 13:43
  • Silly question: Have you checked your browsers dev tools 'network' tab, and see that its not returning as a Server code 500? – IncredibleHat Jun 29 '18 at 13:55
  • what should be the location of the header? -- i mean 'send to page' –  Jun 29 '18 at 14:08
  • @IncredibleHat can you tell me again the things you wanted me to put at the top of the script – j.edgar Jun 29 '18 at 14:18
  • Useful for debugging (not for 500 errors though) `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` – IncredibleHat Jun 29 '18 at 14:20

1 Answers1

0

Make sure that your query

$sql = mysqli_query($con,"SELECT * FROM users where username = '".$username."'");

$user = $sql->fetch_assoc();

not throwing any mysql error

if it will throw the error header will not work. Because before header we can not print anything