Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does the header work in php?

Tags:

php

header

Going through the php.net site, it had an example for header, which says would give me error. I copied it, and executed on on WAMP, but it didn't showed me any error, but did redirect 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/');
?>

Just wanted to know, if its a right behavior on my WAMP, or its an error, or if I have any particular settings active in php.ini file which is making this work!!!. Let me know if anyone needs my php.ini to be copied here!!

Thanks, Tanmay

like image 707
jtanmay Avatar asked Aug 19 '10 19:08

jtanmay


People also ask

What is the use of header () function?

The header() function sends a raw HTTP header to a client. It is important to notice that the header() function must be called before any actual output is sent!

Where is header located in PHP?

Basically, there are two types of header calls. One is header which starts with string “HTTP/” used to figure out the HTTP status code to send. Another one is the “Location” which is mandatory. replace: It is optional which indicates whether the header should add a second header or replace previous.

What is header content type in PHP?

The Content-Type header is used to indicate the media type of the resource. The media type is a string sent along with the file indicating the format of the file. For example, for image file its media type will be like image/png or image/jpg, etc. In response, it tells about the type of returned content, to the client.

How can I add header in PHP?

You can do it by using include_once() function in php. Construct a header part in the name of header. php and construct the footer part by footer.


1 Answers

It sounds like you have output_buffering enabled.

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

Standard configuration would be to error because data has already been output, and headers need to come first. Output buffering would allow headers to appear in code after other output, but it would still output the headers first due to the buffer.

like image 146
Fosco Avatar answered Oct 04 '22 03:10

Fosco