使用php get_headers Content-Type检查是否可以使用swf url

I'm trying to drop invalid URLs from my flash games site. Here is my code:

function valid($URL1) {
$headers = get_headers($URL1);
$headers = substr($headers[8],38,5);//leaves only flash word 
if ($headers=='flash')
return true; else   return false;
}
$URL1='http://www.ht83.com/medias/media-16/ht83com-cde-house-decoration.swf';
if(valid($URL1))
echo 'SWF are word>' ;

that code return true even Content-Type are not swf .

by the way I already tried

$headers=$headers['Content-Type'];

but give me no result . When I tried

var_dump($headers);

return this for valid SWF URL http://www.ht83.com/medias/media-16/ht83com-spongebob-squarepants-gone-fishing.swf

array(9) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(35) "Date: Sat, 01 Feb 2014 01:36:35 GMT" [2]=> string(144) "Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8m DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_fcgid/2.3.5" [3]=> string(20) "Accept-Ranges: bytes" [4]=> string(22) "Content-Length: 342771" [5]=> string(39) "Cache-Control: max-age=62208000, public" [6]=> string(38) "Expires: Mon, 03 Mar 2014 01:36:35 GMT" [7]=> string(17) "Connection: close" [8]=> string(43) "Content-Type: application/x-shockwave-flash" }

AND this for the Invalid SWF URL http://www.ht83.com/medias/media-16/ht83com-cde-house-decoration.swf

array(12) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(35) "Date: Sat, 01 Feb 2014 01:40:06 GMT" [2]=> string(144) "Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8m DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_fcgid/2.3.5" [3]=> string(24) "X-Powered-By: PHP/5.2.16" [4]=> string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT" [5]=> string(77) "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0" [6]=> string(16) "Pragma: no-cache" [7]=> string(62) "Set-Cookie: PHPSESSID=359cf391842876b3cc79066dcc3a08f4; path=/" [8]=> string(21) "Vary: Accept-Encoding" [9]=> string(52) "Cache-Control: max-age=600, private, must-revalidate" [10]=> string(17) "Connection: close" [11]=> string(23) "Content-Type: text/html" }

So their is any easier way to get correct Content-Type of URL .

Looks like I used get_headers() in numeric only . this code from Sean Johnson works

function valid($URL) {
$headers = get_headers($URL, 1);//
return stripos($headers['Content-Type'],"application/x-shockwave-flash")!==false;
}
查看全部
douyu0792
douyu0792
2014/02/01 01:52
  • string
  • php
  • content-type
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复