- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is header() function in PHP?
The header() function is an predefined PHP native function.With header() HTTP functions we can control data sent to the client or browser by the Web server before some other output has been sent.
The header function sets the headers for an HTTP Response given by the server. We can do all sorts of things using the header function in PHP like Change page location, set timezone, set caching control, etc...
Some of the important uses of the header() in PHP are listed below:
It is used to redirect a from one web page to another web page in PHP.
header('Location:give your url here');
Set Content-Type in header response:
PHP defaults to sending Content-Type:text/html.If we want to change the Content-Type, we can achieve that with the header() function.
Generated PDF file :header('Content-Type: application/pdf'); Return response in json format:header('Content-Type: application/pdf');.
Set HTTP Status in the header response.
header("HTTP/1.0 404 Not Found");
Sent the response to a browser with no cache.
The below example helps to prevent caching by sending header information which overrides browser setting to not-cache.
header("Cache-Control: no-cache, must-revalidate");
- header() function in PHP
- What is explode() function in PHP?
- What is implode() function in PHP?
- PHP – Compose a MIME header field using iconv_mime_encode() function
- What is the TCP Segment Header?
- What is Authentication Header (AH) format?
- PHP – How to decode a MIME header field using iconv_mime_decode() function?
- What is the maximum size of HTTP header values?
- What is the common header format of Python files?
- PHP – Encode string for MIME header using mb_encode_mimeheader()
- What is traits in PHP?
- What is .htaccess in PHP?
- What is method overloading in PHP?
- What is dependency injection in PHP?
- What is Exception Handling in PHP ?