Jump to content

Help with PHP Warning


Recommended Posts

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"); ?>


redirect.php line 81:


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.

Link to comment
Share on other sites

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.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.