查看“Jquery CDN协议相对url”是否存在


Check if the Jquery CDN protocol relative url exists PHP

我试图通过PHP查看JQuery CDN是否存在

就是Paul Irish在这里所做的,只不过用的是PHP。

http://paulirish.com/2010/the-protocol-relative-url/

我正在尝试以下,但它不工作。这可能没有http/https吗?

这是基于我如何通过PHP检查URL是否存在?

    $jquery_cur = '1.9.1'; // JQuery Version
    $jquery_cdn = '//code.jquery.com/jquery-'.$jquery_cur.'.min.js';
    $jquery_local = '/assets/js/libs/jquery-'.$jquery_cur.'.min.js';
    $jquery_ver = $jquery_cdn;  //Load the Jquery CDN version by default
    $cdn_headers = @get_headers($jquery_ver);
    if(strpos($cdn_headers[0], '404 Not Found')) {
        $jquery_ver = $jquery_cdn;
    }
    else {
        $jquery_ver = $jquery_local;
    }

嗨,检查这个解决方案,你检查头没有任何协议,你需要添加http或https来检查文件。测试它是否有网络连接

$jquery_cur = '1.9.1'; // JQuery Version
        $jquery_cdn = '//code.jquery.com/jquery-'.$jquery_cur.'.min.js';
        $jquery_local = '/assets/js/libs/jquery-'.$jquery_cur.'.min.js';
        $jquery_ver = $jquery_cdn;  //Load the Jquery CDN version by default
        $jquery_url = ( $_SERVER['SERVER_PORT'] == 443 ? "https:" : "http:").$jquery_cdn;
        $test_url = @fopen($jquery_url,'r');
        if($test_url === False) {
        $jquery_ver = $jquery_local;
        }
        echo $jquery_ver;
与get_header

$headers = @implode('', @get_headers($jquery_url));
$test_url = (bool)preg_match('#^HTTP/.*'s+[(200|301|302)]+'s#i', $headers);
if($test_url === False) {
     $jquery_ver = $jquery_local;
 }
echo $jquery_ver;