Change language

PHP Header () function

Syntax:
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).
Return Values:This function does not return any value.Example 1:
// 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

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically