Skip to content

Instantly share code, notes, and snippets.

@gostrafx
Last active May 19, 2019 22:18
Show Gist options
  • Save gostrafx/348670111e7b2972a0e892de102aaddd to your computer and use it in GitHub Desktop.
Save gostrafx/348670111e7b2972a0e892de102aaddd to your computer and use it in GitHub Desktop.
Header php
<?php

// Utilisez cette tête instruction pour corriger 404 têtes
// Produit par url rewriting ...
header('HTTP/1.1 200 OK');

// Page n'a pas été trouvé:
header('HTTP/1.1 404 Not Found');

// Accès interdit:
header('HTTP/1.1 403 Forbidden');

// La page déplacée de façon permanente doit être utilisé pour
// toutes les restrictions, parce que les moteurs de recherche savent
// ce qui se passe et peut facilement mettre à jour leurs urls.
header('HTTP/1.1 301 Moved Permanently');

// Erreur du serveur
header('HTTP/1.1 500 Internal Server Error');

// Redirection vers un nouvel emplacement:
header('Location: http://www.example.org/');

// Rediriger avec un retard:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
// vous pouvez également utiliser la syntaxe HTML:
// <meta http-equiv="refresh" content="10;http://www.example.org/ />

// remplacer X-Powered-By valeur
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');

// langue de contenu (en anglais =)
header('Content-language: en');

// Dernière modification (bon pour la mise en cache)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

// Tête pour dire au navigateur que le contenu
// Ne se changer
header('HTTP/1.1 304 Not Modified');

// Définir la longueur du contenu (bon pour la mise en cache):
header('Content-Length: 1234');

// En-têtes pour télécharger:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// Charger le fichier à envoyer:
readfile('example.zip');

// Désactiver la mise en cache du document en cours:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date dans le passé
header('Pragma: no-cache');

// Définir le type de contenu:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); // plain text file
header('Content-Type: image/jpeg'); // JPG picture
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash'); // Flash animation

// Montrer signe dans la case
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment