top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of header function in PHP?

0 votes
779 views
What is the use of header function in PHP?
posted May 23, 2014 by Amanpreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

+1 vote

The header function sends a raw HTTP header to client. It can be used for redirection of Pages.

answer May 26, 2014 by Karamjeet Singh
+1 vote

The header() function is used to a raw HTTP header to a client.

Syntax
header(string,replace,http_response_code)

string              Required. Specifies the header string to send
replace             Optional. Indicates whether the header should replace previous 
                    or add a second header. Default is TRUE (will replace). 
                    FALSE (allows multiple headers of the same type)
http_response_code  Optional. Forces the HTTP response code to the specified value

EXAMPLES
1) Redirect the browser to a Page

<?php
header("Location: http://tech.QueryHome.com/"); /* Redirect browser */
?>

2) Use of Replace variable

<?php
header('WWW-Authenticate: Negotiate');
header('WWW-Authenticate: NTLM', false);
?>
answer May 30, 2014 by Santosh Prasad
0 votes

header() is used to send a raw HTTP header.It is important to notice that header() must be called before any actual output is sent..........

syntax:-header(string,replace,http_response_code)

answer May 30, 2014 by Vrije Mani Upadhyay
0 votes

The header() function sends a raw HTTP header to a client.

Syntax

header(string,replace,http_response_code)

It is important to notice that header() must be called before any actual output is sent (In PHP 4 and later, you can use output buffering to solve this problem):

Example

<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.QueryHome.com/');
exit;
?>

Credit: http://php.net/manual/en/function.header.php

answer Mar 11, 2016 by Ashish Kumar Khanna
...