「PHPの入門」PHPでheader()関数の使い方

//エンコーディングを定義する
header( 'Content-Type:text/html;charset=utf-8 ');

//Atom
header('Content-type: application/atom+xml’);

//CSS
header('Content-type: text/css’);

//Javascript
header('Content-type: text/javascript’);

//JPEG Image
header('Content-type: image/jpeg’);

//JSON
header('Content-type: application/json’);

//PDF
header('Content-type: application/pdf’);

//RSS
header('Content-Type: application/rss+xml; charset=utf-8’);

//Text (Plain)
header('Content-type: text/plain’);

//XML
header('Content-type: text/xml’);

// ok
header('HTTP/1.1 200 OK’);

//404を設定:
header('HTTP/1.1 404 Not Found’);

//永久にリダイレクトされるようにアドレスを設定
header('HTTP/1.1 301 Moved Permanently’);

//新しいアドレスに移動
header('Location: http://www.arkgame.com/’);

//ファイル遅延ステアリング:
header('Refresh: 10; url=http://www.arkgame.com/’);
print 'You will be redirected in 10 seconds’;
//html文法を使って実現することができる
// <meta http-equiv="refresh" content="10;http://www.arkgame.com/ />

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

//ドキュメント言語
header('Content-language: en’);

//ブラウザの最終修正時間
$time = time() – 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s’, $time).’ GMT’);

//ブラウザの修正内容
header('HTTP/1.1 304 Not Modified’);

//コンテンツの長さを設定
header('Content-Length: 1234’);

//ダウンロードタイプを設定
header('Content-Type: application/octet-stream’);
header('Content-Disposition: attachment; filename="example_startnews24.zip"');
header('Content-Transfer-Encoding: binary’);
// load the file to send:
readfile('example.zip’);

// ドキュメントのキャッシュを無効
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate’);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT’); // Date in the past
header('Pragma: no-cache’);

//コンテンツタイプを設定:
header('Content-Type: text/html; charset=shift-jis’);
header('Content-Type: text/html; charset=utf-8’);
header('Content-Type: text/plain’); //プレーンテキスト
header('Content-Type: image/jpeg’); //JPG***
header('Content-Type: application/zip’); // ZIPファイル
header('Content-Type: application/pdf’); // PDFファイル
header('Content-Type: audio/mpeg’); // オーディオファイル
header('Content-Type: application/x-shockw**e-flash’); //Flash動画

//ログインダイアログボックスが
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’;

Development

Posted by arkgame