-2
<?php 
if(!isset($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != "on")
{
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);

header("Location: https://somesite.com/it");
die('should have redirected by now');

} 
?>

This is the actual code I am using there are no spaces or anything before the first line of code.

Returns: Warning: Cannot modify header information - headers already sent by (output started at /home/somesite/public_html/it/test.php:1) in /home/somesite/public_html/iq/test.php on line 8 should have redirected by now

Why does it say that I have sent headers on the first line? How do I fix this?

Peter S McIntyre
  • 409
  • 4
  • 12
  • You cannot send headers after `flush()`. – GrumpyCrouton Jul 31 '17 at 16:13
  • 1
    This looks like a better answer that I gave, have a look at https://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite – RiggsFolly Jul 31 '17 at 16:41
  • That answer worked to put things into https, however I still need to be able to change headers. Since there is nothing wrong with my code what would cause the headers to not work as they are? – Peter S McIntyre Jul 31 '17 at 17:20

1 Answers1

2

Don't call flush(); before you send the headers. It sends the output buffer, so it triggers the end of the header sending phase.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Tried that still Warning: Cannot modify header information - headers already sent by (output started at /home/somesite/public_html/iq/test.php:1) in /home/somesite/public_html/iq/test.php on line 7 should have redirected by now – Peter S McIntyre Jul 31 '17 at 16:15