Last active
March 8, 2022 18:32
-
-
Save guimadaleno/9359656 to your computer and use it in GitHub Desktop.
Some header manipulations using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# 301 Moved Permanently (redirect) | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: http://www.domain.com/newpage.html'); | |
# 404 Page Not Found | |
header('HTTP/1.1 404 Not Found'); | |
# 503 Service not available | |
header('HTTP/1.1 503 Service Temporarily Unavailable'); | |
header('Status: 503 Service Temporarily Unavailable'); | |
header('Retry-After: 60'); | |
# Displaying a PDF file | |
header('Content-Type: application/pdf'); | |
echo file_get_contents('example.pdf'); | |
# Force browser to not cache | |
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); | |
header('Cache-Control: no-store, no-cache, must-revalidate'); | |
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); | |
header('Pragma: no-cache'); | |
# Force browser to make file 'downloadable' | |
$file = "file.zip"; | |
header('Content-Disposition: attachment; filename=' . urlencode($file)); | |
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($file)); | |
echo file_get_contents($file); | |
# Cya :P | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment