我正在尝试从我的Flash游戏网站中删除无效网址。 这是我的代码:
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>' ;
该代码返回true,即使Content-Type也不是swf。
按照我已经尝试的方式
$headers=$headers['Content-Type'];
但是没有结果。 我试过的时候
var_dump($headers);
返回此内容以获取有效的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)“日期: 星期六,01二月2014 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] => 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) “内容类型:application / x-shockwave-flash”}
这是无效的SWF网址 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)“日期: 星期六,01二月2014 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)“Expires:Thu,1981年11月19日08:52:00 GMT”[5] =>串(77) “缓存控制:无存储,无缓存,必须重新验证,后检查= 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“}
因此,他们可以更轻松地获取正确的内容类型的网址。
看起来我只在数字中使用了get_headers()。这段来自肖恩·约翰逊的代码
function valid($URL) {
$headers = get_headers($URL, 1);//
return stripos($headers['Content-Type'],"application/x-shockwave-flash")!==false;
}
答案 0 :(得分:1)
根据get_headers documentation的第一个示例,如果您希望能够通过其键值访问标题,则需要使用第二个参数。
试试这个:
function valid($URL) {
$headers = get_headers($URL,1);
return stripos($headers['Content-Type'],"flash")!==false;
}
答案 1 :(得分:0)
您的代码假设Content-Type标头始终是服务器返回的第9个标头,但情况并非如此。
您需要遍历标题并仅检查正确的标题(即以Content-Type:
开头的标题。)