douyu0792 2014-02-01 01:52
浏览 539
已采纳

使用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;
}
  • 写回答

2条回答 默认 最新

  • doujuchuan9915 2014-02-01 02:11
    关注

    According to the very first example of the get_headers documentation you need to use the second argument if you want to be able to access the header by it's key value.

    Try this:

    function valid($URL) {
        $headers = get_headers($URL,1);
        return stripos($headers['Content-Type'],"flash")!==false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题