0

I have a php file that should be sending response headers, but it isn't. Here is the networking tab of both the local server and the remote server. As you can see, the local server is sending many different headers, but the remote server isn't sending any.

enter image description hereenter image description here

I sent all the response headers using php header(), but since this works perfectly on the local server, im guessing it's a server configuration issue? If anyone has had this issue before, please share an answer - i've been pulling my hair out over this for 3 days now -_-

EDIT thought the php code might help:

<?php 
error_reporting(E_ALL);
//disable browser caching !!IMPORTANT
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: POST, GET"); 
header("Access-Control-Allow-Headers: Random");
header("Access-Control-Expose-Headers: Random");
header("Access-Control-Request-Headers: Random");

theres no whitespace before this php code. Also if there was an issue with this code, surely it wouldnt work on my local server?

Thanks, Josh

Josh Lyness
  • 102
  • 1
  • 12
  • Does the production server use output buffering by chance? And are both responses served through the same SAPI? – Gordon Nov 13 '17 at 11:17
  • Second image is not corresponding to about.php response. The response is about view-search-freight.php file. – Ceylan B. Nov 13 '17 at 11:18
  • @CeylanB. ahh yeah sorry its the same, since I use a php include() on both files – Josh Lyness Nov 13 '17 at 11:20
  • @Gordon I'm not sure the SAPI or output buffering for the remote server, but i can find out if thats a common reason for this sort of issue? – Josh Lyness Nov 13 '17 at 11:21
  • output buffering would prevent any "headers already sent errors", which could would cause later set headers to get discarded. SAPI is important because some SAPIs dont support setting headers. – Gordon Nov 13 '17 at 11:24
  • 1
    Possible duplicate of [header redirect not working on server but working on localhost](https://stackoverflow.com/questions/15398808/header-redirect-not-working-on-server-but-working-on-localhost) – Ceylan B. Nov 13 '17 at 11:59
  • @CeylanB. yeah it is a duplicate I guess. But considering the amount of time I spent googling the issue, I never came across that question - probably because the title is specific to his situation. – Josh Lyness Nov 13 '17 at 13:17
  • 1
    @JoshLyness Yes you are right. – Ceylan B. Nov 13 '17 at 13:19

1 Answers1

2

Same problem is here;

Try to use ob_start(); just after <?php and use ob_end_flush(); at the end of your document.
Ceylan B.
  • 564
  • 9
  • 23
  • I think it must be a server config or something, this actually fixed it. Why? – Josh Lyness Nov 13 '17 at 11:33
  • 1
    You can't set headers after page load is complete. If you want to set headers it must be the first process. So when you use ob_start, it starts the buffering. Codes, between ob_start and ob_end_flush, will be buffered. As soon as ob_end_flush is called, content of buffer is loaded at once. – Ceylan B. Nov 13 '17 at 11:57