AustDevNerd Posted February 20 Share Posted February 20 Hello experts, I have a problem and can't find the reason, please help. PHP Warning: Cannot modify header information - headers already sent by (output started at index.html:1) in redirect.php on line 81 index.html starts with: <!-- <? include("redirect.php"); ?> --> <!DOCTYPE HTML> redirect.php line 81: header('Location:http://www.blah.com/blah.html'); The script is going to prevent user with certain IPs to view specific pages. Not used echo or print in redirect.php. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 20 Share Posted February 20 "output started at index.html:1" You cannot use headers if there has been any output. The message tells you exactly where, and looking at that line, I don't know why you have it in the first place... Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 21 Share Posted February 21 In addition to the answer to your question from requinix, you have made some ill advised re-configuration of your server, in order to process .html files as if they were php scripts. You should undo that, and use an index.php instead. I will add that you could get around the issue of automatic output via output buffering, but I wouldn't advise trying to get around this issue with that solution when you have something so unsophisticated and clearly a 1st step towards actual implementation of what you really want. Typically what people do these days is implement some form of the "front controller" pattern. Under this pattern, the index.php becomes your front controller/bootstrap/kernel/router, and can also do the security checks (filtering) you require. What you want then, is to have ALL requests for your site run through your front controller. It can then take the requested "virtual" path, by parsing the request URL, and loading the code you want to make available, or prompt for authentication, return whatever HTTP response code you want, etc. This page from the symfony documentation illustrates ways to setup various different web server configurations to use index.php as the front controller: https://symfony.com/doc/current/setup/web_server_configuration.html It's just a start, but once you get the idea you can come up with some simple static routing just using something as simple as a case statement, and require_once() of the code you want to run from there. One of the first sites I ever worked on essentially did just that for the majority of its routing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.