void header ($header, $replace = TRUE, $http_response_code)Parameters:this the function takes three parameters as above and described below:
- $header:this parameter contains the header line. There are two types of header calls. The first header begins with the string "HTTP /", which is used to define the HTTP status code to send. The second case of the header - "Location:". This is a required parameter.
- $replace:this is an optional parameter. It means that the heading should replace the previous one or add a second heading. The default is True (override). If $replace is False then it forces multiple headers of the same type.
- $http_response_code:This is an optional parameter. This forces the HTTP response code to the specified value (PHP 4.3 and up).
// PHP program for describing the header function
// Redirect browser
header (
"Location: http://www.engineerforengineer.org "
);
// the code below does not run
// when redirecting
exit
;
?>
Output:This will change location of header, ie redirect to the URL
Example 2:
// PHP program to describe the header function
// Set past date
header (
"Expires: Sun, 25 Jul 1997 06:02:34 GMT"
);
header (
"Cache-Control: no-cache"
);
header (
"Pragma: no-cache"
);
?>
Hello World! < / p>
header list ->
print_r (headers_list());
?>
< / html >
Output:
Hello World! Array ([0] = > X-Powered-By: PHP / 7.0.33 [1] = > Expires: Sun, 25 Jul 1997 06:02:34 GMT [2] = > Cache-Control: no- cache [3] = > Pragma: no-cache)
The above example helps prevent caching by sending header information that overrides browser settings so that it won’t be cached.Note:The header() functions in this example are used multiple times because one header is allowed to be sent at a time (since PHP 4.4) to prevent header attacks.Scope : - Change page location
- Set time zone
- Set cache control
- Start push download
- Send HTTP Status
Link: http://php.net/manual/en/function.header.php