How does the header work in php?

After going through the php.net website, he got an example for a heading that says this will give me an error. I copied it and ran it on WAMP, but it did not show me any error, but redirected to the site.

<html> <?php /* This should give an error (but it doesn't!). Note the output * above, which is before the header() call */ header('Location: http://www.example.com/'); ?> 

I just wanted to know if this is the correct behavior on my WAMP or its error, or if I have any specific settings active in the php.ini file that does this job !!!. Let me know if someone needs my php.ini to copy here.

Thanks Tanmay

+6
php header
source share
2 answers

It looks like you have the output_buffering function.

http://php.net/manual/en/outcontrol.configuration.php

The standard configuration will be associated with an error, because the data is already output, and the headers should be the first. Buffering the output would allow the headers to appear in the code after another output, but it would still output the headers due to the buffer.

+4
source share

Headings are sent as soon as any text is sent to the browser and can only be sent once. once sent, headers are sent along with it, so try the header function after wll discards the already sent header errors.

0
source share

All Articles