La funzione header() invia header HTTP al browser.
Redirect
// Redirect semplice
header("Location: /dashboard.php");
exit(); // Importante!
// Redirect con status code
header("Location: /nuova-pagina.php", true, 301); // Moved Permanently
header("Location: /temp.php", true, 302); // Temporary RedirectContent-Type
// JSON
header("Content-Type: application/json");
// Download file
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename="file.pdf"");
// XML
header("Content-Type: text/xml");Cache control
// No cache
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");Importante
header() deve essere chiamata PRIMA di qualsiasi output HTML.