SQLの窓

2013年11月28日


file_get_contents(HTTP ラッパー)を使ったWEBアクセスのhttpヘッダを取得する / $http_response_header という特別な変数

$http_response_header という特別な変数に配列として格納されます。関数内で HTTP ラッパー が使用された場合は、ローカルスコープとなり、$http_response_header は、関数内でのみ有効ですが、global で宣言すると外部からも参照可能になります。
<?php
function get_contents_1() {
	file_get_contents("http://winofsql.jp/toolbox.gif");
	var_dump($http_response_header);
}
get_contents_1();
var_dump($http_response_header);

function get_contents_2() {

	global $http_response_header;

	file_get_contents("http://winofsql.jp/toolbox.gif");
	var_dump($http_response_header);
}

get_contents_2();
var_dump($http_response_header);
?>


以下が実行結果ですが、一回目のセットで、関数外から参照した場合は NULL となっています。

array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Wed, 27 Nov 2013 16:36:58 GMT"
  [2]=>
  string(58) "Server: Apache/1.3.42 (Unix) mod_ssl/2.8.31 OpenSSL/0.9.8e"
  [3]=>
  string(44) "Last-Modified: Wed, 09 Feb 2011 12:41:58 GMT"
  [4]=>
  string(19) "ETag: "88-4d528b96""
  [5]=>
  string(20) "Accept-Ranges: bytes"
  [6]=>
  string(19) "Content-Length: 136"
  [7]=>
  string(17) "Connection: close"
  [8]=>
  string(23) "Content-Type: image/gif"
}
NULL
array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Wed, 27 Nov 2013 16:36:58 GMT"
  [2]=>
  string(58) "Server: Apache/1.3.42 (Unix) mod_ssl/2.8.31 OpenSSL/0.9.8e"
  [3]=>
  string(44) "Last-Modified: Wed, 09 Feb 2011 12:41:58 GMT"
  [4]=>
  string(19) "ETag: "88-4d528b96""
  [5]=>
  string(20) "Accept-Ranges: bytes"
  [6]=>
  string(19) "Content-Length: 136"
  [7]=>
  string(17) "Connection: close"
  [8]=>
  string(23) "Content-Type: image/gif"
}
array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Wed, 27 Nov 2013 16:36:58 GMT"
  [2]=>
  string(58) "Server: Apache/1.3.42 (Unix) mod_ssl/2.8.31 OpenSSL/0.9.8e"
  [3]=>
  string(44) "Last-Modified: Wed, 09 Feb 2011 12:41:58 GMT"
  [4]=>
  string(19) "ETag: "88-4d528b96""
  [5]=>
  string(20) "Accept-Ranges: bytes"
  [6]=>
  string(19) "Content-Length: 136"
  [7]=>
  string(17) "Connection: close"
  [8]=>
  string(23) "Content-Type: image/gif"
}

ただ、この場合取得する事のできる最大値は 1024 のようです。




【PHP + 通信の最新記事】
posted by lightbox at 2013-11-28 01:45 | PHP + 通信 | このブログの読者になる | 更新情報をチェックする
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり