Modify HTTP Headers


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Use this header instruction to fix 404 headers
  2. // produced by url rewriting...
  3. header('HTTP/1.1 200 OK');
  4.  
  5. // Page was not found:
  6. header('HTTP/1.1 404 Not Found');
  7.  
  8. // Access forbidden:
  9. header('HTTP/1.1 403 Forbidden');
  10.  
  11. // The page moved permanently should be used for
  12. // all redrictions, because search engines know
  13. // what's going on and can easily update their urls.
  14. header('HTTP/1.1 301 Moved Permanently');
  15.  
  16. // Server error
  17. header('HTTP/1.1 500 Internal Server Error');
  18.  
  19. // Redirect to a new location:
  20. header('Location: http://www.example.org/');
  21.  
  22. // Redriect with a delay:
  23. header('Refresh: 10; url=http://www.example.org/');
  24. print 'You will be redirected in 10 seconds';
  25.  
  26. // you can also use the HTML syntax:
  27. // <meta http-equiv="refresh" content="10;http://www.example.org/ />
  28.  
  29. // override X-Powered-By value
  30. header('X-Powered-By: PHP/4.4.0');
  31. header('X-Powered-By: Brain/0.6b');
  32.  
  33. // content language (en = English)
  34. header('Content-language: en');
  35.  
  36. // last modified (good for caching)
  37. $time = time() - 60; // or filemtime($fn), etc
  38. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
  39.  
  40. // header for telling the browser that the content
  41. // did not get changed
  42. header('HTTP/1.1 304 Not Modified');
  43.  
  44. // set content length (good for caching):
  45. header('Content-Length: 1234');
  46.  
  47. // Headers for an download:
  48. header('Content-Type: application/octet-stream');
  49. header('Content-Disposition: attachment; filename="example.zip"');
  50. header('Content-Transfer-Encoding: binary');
  51. // load the file to send:
  52. readfile('example.zip');
  53.  
  54. // Disable caching of the current document:
  55. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  56. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  57. header('Pragma: no-cache');
  58.  
  59. // set content type:
  60. header('Content-Type: text/html; charset=iso-8859-1');
  61. header('Content-Type: text/html; charset=utf-8');
  62. header('Content-Type: text/plain'); // plain text file
  63. header('Content-Type: image/jpeg'); // JPG picture
  64. header('Content-Type: application/zip'); // ZIP file
  65. header('Content-Type: application/pdf'); // PDF file
  66. header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
  67. header('Content-Type: application/x-shockwave-flash'); // Flash animation
  68.  
  69. // show sign in box
  70. header('HTTP/1.1 401 Unauthorized');
  71. header('WWW-Authenticate: Basic realm="Top Secret"');
  72. print 'Text that will be displayed if the user hits cancel or ';
  73. print 'enters wrong login data';

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.