Hi friends, In this post i would like to share my knoweldge about redirection , 404 ( Page not found error message) ,service not avialable(503), CSS , Javascript , For the images and application type ( PDF ,…).
For above requirements we can use php headers to solve the issues.
1) 301 moved permanently (redirect):
1 2 3 4 5 |
2) 302 moved temporarily(redirect):
3) 404 Page Not Found:
1 2 3 |
4) Service not avaliable:
1 2 3 4 5 |
5) CSS:
1 2 3 |
6) Javascript header:
1 2 3 |
7) Images:
7.1) For JPEG(jpg):
1 2 3 |
7.2) For PNG:
1 2 3 |
7.3)For BMP:
1 2 3 |
8 ) PDF (output pdf with php):
1 2 3 4 |
9) Cache (force browsers not to cache files):
1 2 3 4 5 6 |
10) Download dialog:
1 2 3 4 5 6 7 8 9 | <?php header('Content-Disposition: attachment; filename=' . urlencode($f)); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); header('Content-Description: File Transfer'); header('Content-Length: ' . filesize($f)); echo file_get_contents($f); ?> |
11) Authentication (force the browser to pop up a Username/Password input window) – only available when PHP is running as an Apache module:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="The Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'If cancel is pressed this text shows'; die(); } else { //always escape your data// $user='user_name'; $pass='password'; if($_SERVER['PHP_AUTH_USER']==$user && $_SERVER['PHP_AUTH_PW']==$pass){ echo 'Authorized'; } } ?> |
2 Comments
how to convert feeds to html using javascript and php - ANIL KUMAR PANIGRAHI 's Blog · September 16, 2011 at 3:09 am
[…] 4)Examples for PHP Headers (301,302,404,…) http://www.anil2u.info/2011/04/examples-for-php-headers-301302404/ 5)how to include external js,css files with javascript […]
How to include external js,css files with javascript - Anil Labs · June 2, 2012 at 11:06 am
[…] For more php headers http://www.anil2u.info/2011/04/examples-for-php-headers-301302404/ […]