«È¤á¤f¸O±ÀÂË¡AÀu½è·h®aªA°È
½u¤W§K¶O¦ô»ù¡A·h®a­º¿ï
¸ËæC³]­p¼o±óª«³B²z¡BªA°ÈÀu¥ý¡B»ù·G¹ê´f
°t¦X«×°ª¡AÅwªï¨Ó¹q¸ß»ù

­º­¶  ¡E  j2h ½×¾Â ¡E µ{¦¡³]­p°Q½×     ¡E 

[php] phpÀò¨úºô­¶header«H®§ªº4ºØ¤èªk

©ÐªF¡Gjack
µoªí®É¶¡¡G2015-12-07
[ÀËÁ|]


phpÀò¨úºô­¶header«H®§ªº¤èªk¦hºØ¦h¼Ë¡A´Nphp»y¨¥¨Ó»¡¡A§Úª¾¹Dªº¤èªk¦³4ºØ, ¤U­±³v¤@Äm¤W¡C

¤èªk¤@¡G¨Ï¥Îget_headers()¨ç¼Æ

±ÀÂË«ü¼Æ: ¡¹¡¹¡¹¡¹¡¹

get_header¤èªk³Ì²³æ¥u­n¨â¦æ¥N½X§Y¥i·d©w¡C¦p¤U¡G

$thisurl = \"http://www.lao8.org/\";
print_r(get_headers($thisurl, 1));
±o¨ìªºµ²ªG爲¡G

Array
(
[0] => HTTP/1.1 200 OK
[Cache-Control] => max-age=86400
[Content-Length] => 76102
[Content-Type] => text/html
[Content-Location] => http://www.lao8.org/index.html
[Last-Modified] => Fri, 19 Jul 2013 03:52:30 GMT
[Accept-Ranges] => bytes
[ETag] => \"50bc48643384ce1:5cb3\"
[Server] => Microsoft-IIS/6.0
[X-Powered-By] => ASP.NET
[Date] => Fri, 19 Jul 2013 09:06:39 GMT
[Connection] => close
)
¤èªk¤G¡G¨Ï¥Îhttp_response_header

±ÀÂË«ü¼Æ: ¡¹¡¹¡¹

http_response_headerf¤èªk¤]«Ü²³æ¡A¶È¤T¦æ¡G

$thisurl = \"http://www.lao8.org\";
$html = file_get_contents($thisurl );
print_r($http_response_header);
±o¨ìªºµ²ªG爲¡G

Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: max-age=86400
[2] => Content-Length: 76102
[3] => Content-Type: text/html
[4] => Content-Location: http://www.lao8.org/index.html
[5] => Last-Modified: Fri, 19 Jul 2013 03:52:30 GMT
[6] => Accept-Ranges: bytes
[7] => ETag: \"50bc48643384ce1:5cb3\"
[8] => Server: Microsoft-IIS/6.0
[9] => X-Powered-By: ASP.NET
[10] => Date: Fri, 19 Jul 2013 09:06:41 GMT
[11] => Connection: close
)
¤èªk¤T¡G¨Ï¥Îstream_get_meta_data()¨ç¼Æ

±ÀÂË«ü¼Æ: ¡¹¡¹¡¹

¨Ï¥Îstream_get_meta_data()¥N½X¤]¥u»Ý¤T¦æ¡G

$thisurl = \"http://www.lao8.org/\";
$fp = fopen($thisurl, \'r\');
print_r(stream_get_meta_data($fp));
±o¨ìªºµ²ªG爲¡G

Array
(
[wrapper_data] => Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: max-age=86400
[2] => Content-Length: 76102
[3] => Content-Type: text/html
[4] => Content-Location: http://www.lao8.org/index.html
[5] => Last-Modified: Fri, 19 Jul 2013 03:52:30 GMT
[6] => Accept-Ranges: bytes
[7] => ETag: \"50bc48643384ce1:5cb3\"
[8] => Server: Microsoft-IIS/6.0
[9] => X-Powered-By: ASP.NET
[10] => Date: Fri, 19 Jul 2013 09:06:41 GMT
[11] => Connection: close
)
[wrapper_type] => http
[stream_type] => tcp_socket
[mode] => r+
[unread_bytes] => 1086
[seekable] =>
[uri] => http://www.lao8.org/
[timed_out] =>
[blocked] => 1
[eof] =>
)
²Ä¥|ºØ¤èªk: ¨Ï¥Îphpªº°ª¯Å¨ç¼Æ CURL()¨ÓÀò¨ú

±ÀÂË«ü¼Æ: ¡¹¡¹¡¹¡¹

¤W­±ªº¤TºØ¤èªk¯àÀò¨ú¤@¯ëªººô­¶header«H®§¡A¦pªG·Q­nÀò¨ú§ó¸Ô²Óªºheader«H®§¤ñ¦pºô­¶¬O§_û£¥Î¤FGZipÀ£ÁY¡C³o®É­Ô¥i¥H¥Îphpªº°ª¯Å¨ç¼Æcurl()¨ÓÀò¨ú¡C

¨Ï¥ÎcurlÀò±oheader¥i¥HÀË´úGZipÀ£ÁY
¥ý¶K¥X¥N½X¡G

$szUrl = \'http://www.lao8.org/\';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $szUrl);
curl_setopt($curl, CURLOPT_HEADER, 1); //¿é¥Xheader«H®§
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //¤£Åã¥Üºô­¶¤º®e
curl_setopt($curl, CURLOPT_ENCODING, \'\'); //¤¹³\\°õ¦ægzip
$data=curl_exec($curl);
if(!curl_errno($curl))
{
$info = curl_getinfo($curl);
$httpHeaderSize = $info[\'header_size\']; //header¦r²Å¦êÅé¿n
$pHeader = substr($data, 0, $httpHeaderSize); //Àò±oheader¦r²Å¦ê
$split = array(\"rn\", \"n\", \"r\"); //»Ý­n®æ¦¡¤Æheader¦r²Å¦ê
$pHeader = str_replace($split, \'
\', $pHeader); //¨Ï¥Î
´«¦æ²Å®æ¦¡¤Æ¿é¥X¨ìºô­¶¤W
echo $pHeader;
}
?>
¿é¥Xµ²ªG¦p¤U¡G



HTTP/1.1 200 OK
Cache-Control: max-age=86400
Content-Length: 15189
Content-Type: text/html
Content-Encoding: gzip
Content-Location: http://www.lao8.org/index.html
Last-Modified: Fri, 19 Jul 2013 03:52:28 GMT
Accept-Ranges: bytes
ETag: \"0268684ce1:5cb3\"
Vary: Accept-Encoding
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Fri, 19 Jul 2013 09:27:21 GMT



  • ÃÙ§Uºô¯¸       

    ¼s§Q¤£°Ê²£-ªO¾ô¦b¦a¥Í®Ú³Ì¹ê¦b--·sªO¯S°Ï«ü¦W«×³Ì°ª¡B­È±o±z«H¿àªº¦n©Ð¥ò
    §¹¾ã©Ð°T¡A©Ð«Î¡B©±­±¼öªùºë¿ïª«¥ó¡A¼s§Q¤£°Ê²£ Àu½è¥ò¤¶¡A©Ð«Î¯²¸î¡B¶R½æ¸ê°T³z©ú¡A¥æ©ö¯u¦w¤ß¡I
    ¼s§Q¤£°Ê²£-·sªO¯S°Ï«ü¦W«×³Ì°ª¡B­È±o±z«H¿àªº¦n©Ð¥ò
    ±zªº¦«¥I,¼s§Q¥Î¤ß¬°±zªA°È



  • ¡@¦@ 0 ¤H¦^À³

    ©m¦W¡G
    §G§i¤º®e¡G