- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
header() function in PHP
The header() function sends a raw HTTP header to a client.
Syntax
header(string,replace,resp_code)
Parameters
string − The header string to send.
replace − Indicates whether the header should replace previous or add a second header.
resp_code − It forces the HTTP response code to the specified value
Return
The header() function returns nothing.
Example
The following is an example to save a generated PDF −
<?php header("Content-type:application/pdf"); header("Content-Disposition:attachment;filename=output.pdf'"); readfile("demo.pdf"); ?>
The file downloaded will be “output.pdf”, whereas the input is “demo.pdf”.
- Related Articles
- What is header() function in PHP?
- PHP – Compose a MIME header field using iconv_mime_encode() function
- PHP – How to decode a MIME header field using iconv_mime_decode() function?
- PHP – Encode string for MIME header using mb_encode_mimeheader()
- PHP – Decode multiple MIME header fields at once using iconv_mime_decode_headers()
- file_exists() function in PHP
- basename( ) function in PHP
- chgrp()function in PHP
- chmod() function in PHP
- chown() function in PHP
- clearstatcache() function in PHP
- copy() function in PHP
- delete() function in PHP
- dirname()function in PHP
- disk_free_space() function in PHP

Advertisements