¤j¤p·h®a¡A¤½¥q¤u¼t¡A¾÷¾¹¡A¿ûµ^ª÷®w ©U§£³B²z¡A¦ô»ù°e½c¡A¥þ¬Ù¦^µ{¡A«~½è«OÃÒ¡C | «Ç¤º³]pº¿ï¡I§K¶O¨ì©²¤V¶q¤Î¦ô»ù ³]p«e¥R¤À°Q½×¡A¥Î¤ß§U±z¹ê²{¹Ú·Q®a¶é¡I |
[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³Ì²³æ¥un¨â¦æ¥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·QnÀò¨ú§ó¸Ô²Óªº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 |