Home > Backend Development > PHP Tutorial > Simple example of php header() function

Simple example of php header() function

WBOY
Release: 2016-07-25 08:58:45
Original
884 people have browsed it
  1. // The result is wrong
  2. // There is already output before calling header()
  3. header('Location: url');
  4. ?>
Copy code

Two: Disable browser cache

  1. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  2. header("Cache-Control: no-cache");
  3. header("Pragma: no-cache") ;
Copy code

Three: Prompt to save a generated PDF file (the Content-Disposition header is used to provide a recommended file name and force the browser to display a save dialog box):

  1. header("Content-type:application/pdf");

  2. // The file will be called downloaded.pdf

  3. header("Content-Disposition:attachment;filename='downloaded.pdf'");

  4. // The PDF source is in original.pdf

  5. readfile("original.pdf");
  6. ? >

Copy the code

Four: Let the visitor's browser display a 404 prompt.

  1. //404 not found
  2. header("Status: 404 Not Found");
  3. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template