Change language

PHP Header () function

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: " );  
// the code below does not run // when redirecting exit ;  
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


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method