header() function in PHP

PHPServer Side ProgrammingProgramming

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”.

raja
Published on 21-Feb-2019 15:59:52
Advertisements