Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems using PHP to send headers using header()
    text
    copied!<p>I am trying to do a small application that send a HTTP request to a website, and gets a HTTP reply. I use the status on the header to see what happened with the request. The code is quiet simple, and short, but somehow I still get the default <code>HTTP/1.1 200 OK</code> instead of my personalize message when everything goes fine. </p> <p>Note: Request can have 2 or 3 parts. 2 parts only authenticates and third part means something should be added. If you have any comments of any other part of the code, I am happy to see them too. note2: token is username, because not sure if I will really need it or not later. </p> <pre><code>&lt;?php if(isset($_POST['usernameUS'])&amp;&amp;isset($_POST['passwordUS'])&amp;&amp;!empty($_POST['usernameUS'])&amp;&amp;!empty($_POST['passwordUS'])) { try { $hostname = ""; $database = ""; $username = ""; $password = ""; $pdo = new PDO("mysql:host=$hostname;dbname=$database", $username, $password); $stmt = $pdo-&gt;prepare("SELECT salt, password FROM users WHERE account=:account"); $stmt-&gt;bindParam(':account', $_POST['usernameUS'], PDO::PARAM_STR); $stmt-&gt;execute(); $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC); $passwordUS = $pdo-&gt;quote($_POST['passwordUS']); $Blowfish_Pre = '$2a$05$'; $Blowfish_End = '$'; $bcrypt_salt = $Blowfish_Pre . $row['salt'] . $Blowfish_End; $hashed_password = crypt($passwordUS, $bcrypt_salt); if ($hashed_password == $row['password']) { if(isset($_POST['message'])) { try { $stmt = $pdo-&gt;prepare("INSERT INTO newData (ip , account , token, message) VALUES (:ip, :username, :token, :message)"); $stmt-&gt;bindParam(':ip', $_POST['usernameUS'], PDO::PARAM_STR); $stmt-&gt;bindParam(':username', $_POST['usernameUS'], PDO::PARAM_STR); $stmt-&gt;bindParam(':token', $_POST['usernameUS'], PDO::PARAM_STR); $stmt-&gt;bindParam(':message', $_POST['message'], PDO::PARAM_STR); $value = $stmt-&gt;execute(); if($value) { header("HTTP/1.1 200 Added"); } else { header("HTTP/1.1 400 Could not add information"); } } catch (PDOException $e) { header("HTTP/1.1 400 Cannot insert message", false); file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND); } } header("HTTP/1.1 200 Authenticated", false); } else { header("HTTP/1.1 400 Incorrect Login Information", false); } } catch(PDOException $e) { header("HTTP/1.1 400 Could not connect", false); file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND); } } else { header( 'Location: http://www.example.com/' ) ; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload