Use of php header functionality

  • 2020-10-23 20:54:02
  • OfStack

The header() function sends the original HTTP header to the client.


<?php
//200  The normal state 
header('HTTP/1.1 200 OK');
// 301  Permanent redirect, remember to emphasize the directed address later  Location:$url
header('HTTP/1.1 301 Moved Permanently');
//  Redirection, that's what it is 302  Temporary redirection 
header('Location: http://www.maiyoule.com/');
//  Settings page 304  There is no change 
header('HTTP/1.1 304 Not Modified');
//  Display the login box, 
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm=" The login information "');
echo ' Information displayed! ';
// 403  Blocking access 
header('HTTP/1.1 403 Forbidden');
// 404  error 
header('HTTP/1.1 404 Not Found');
// 500  Server error 
header('HTTP/1.1 500 Internal Server Error');
// 3 Redirects the specified address after seconds ( That is, refresh to the new page and  <meta http-equiv="refresh" content="10;https://www.ofstack.com/ />  The same )
header('Refresh: 3; url=https://www.ofstack.com/');
echo '10 After the jump to https://www.ofstack.com';
//  rewrite  X-Powered-By  value 
header('X-Powered-By: PHP/5.3.0');
header('X-Powered-By: Brain/0.6b'); 
// Setting the context language 
header('Content-language: en');
 //  Set the last modification time of the page (mostly used to prevent caching) 
$time = time() - 60; // It is recommended to use filetime Function to set the page cache time 
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
//  Set content length 
header('Content-Length: 39344'); 
//  Sets the header file type, which can be used for streaming files or file downloads 
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"'); 
header('Content-Transfer-Encoding: binary');
readfile('example.zip');// Read the file to the client 

// Disable page caching 
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Pragma: no-cache');

// Set the page header information 
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); 
header('Content-Type: image/jpeg'); 
header('Content-Type: application/zip'); 
header('Content-Type: application/pdf'); 
header('Content-Type: audio/mpeg');
header('Content-Type: application/x-shockwave-flash'); 
//....  As for the Content-Type  The value of the   You can look it up  w3c  Document library, which is very rich 
?>


Related articles: