简体   繁体   English

检查swf url是否可用,或者不使用php get_headers Content-Type

[英]Check if swf url avaliable or not using php get_headers Content-Type

I'm trying to drop invalid URLs from my flash games site. 我正在尝试从Flash游戏网站中删除无效的URL。 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 . 即使Content-Type不是swf,该代码也返回true。

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 将其返回为有效的SWF网址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" } array(9){[0] =>字符串(15)“ HTTP / 1.1 200 OK” [1] =>字符串(35)“日期:星期六,2014年2月1日01:36:35 GMT” [2] => string(144)“服务器: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] =>字符串(20)“接受范围:字节” [4] =>字符串(22)“内容长度:342771” [5] =>字符串(39)“高速缓存控制:最大年龄= 62208000,公共” [ 6] =>字符串(38)“到期时间:2014年3月3日,星期一,格林尼治标准时间” [7] =>字符串(17)“连接:关闭” [8] =>字符串(43)“内容类型:application / x-shockwave-flash“}

AND this for the Invalid SWF URL http://www.ht83.com/medias/media-16/ht83com-cde-house-decoration.swf 并针对无效的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" } array(12){[0] =>字符串(15)“ HTTP / 1.1 200 OK” [1] =>字符串(35)“日期:星期六,2014年2月1日01:40:06 GMT” [2] => string(144)“服务器: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)“到期日:1981年11月19日,星期四08:52:00 GMT” [5] => string(77) “高速缓存控制:无存储,无高速缓存,必须重新验证,后检查= 0,预检查= 0” [6] =>字符串(16)“实用程序:无高速缓存” [7] => string(62)“ Set-Cookie:PHPSESSID = 359cf391842876b3cc79066dcc3a08f4; path = /” [8] => string(21)“ Vary:Accept-Encoding” [9] => string(52)“缓存控制:最大年龄= 600,私有,必须重新验证” [10] =>字符串(17)“连接:关闭” [11] =>字符串(23)“内容类型:文本/ html”}

So their is any easier way to get correct Content-Type of URL . 因此,它们是获取正确的URL Content-Type的任何简便方法。

Looks like I used get_headers() in numeric only . 看起来我只在数字中使用了get_headers()。 this code from Sean Johnson works 肖恩·约翰逊的这段代码有效

function valid($URL) {
$headers = get_headers($URL, 1);//
return stripos($headers['Content-Type'],"application/x-shockwave-flash")!==false;
}

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. 根据get_headers文档的第一个示例,如果您希望能够通过其键值访问标头,则需要使用第二个参数。

Try this: 尝试这个:

function valid($URL) {
    $headers = get_headers($URL,1);
    return stripos($headers['Content-Type'],"flash")!==false;
}

Your code is assuming that the Content-Type header will always be the 9th header returned by the server, which is not the case. 您的代码假定Content-Type标头始终是服务器返回的第9个标头,实际情况并非如此。

You will need to loop through the headers and examine only the correct one (that is, the one that starts with Content-Type: ). 您将需要遍历标题并仅检查正确的标题(即,以Content-Type:开头的标题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM