i want simulate server side something so:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript src='/Scripts/jquery-1.3.2.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
And so, i have in php:
function isurlok($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
if(!curl_errno($ch))
$info = curl_getinfo($ch);
curl_close($ch);
if (isset($info) && $info['http_code'] == 200) {
if ($info['http_code'] == 200 ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
For get the available of the resource (in this case the file) and then this:
if ( isurlok ("https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js") {
// remote file
print "<script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>";
print "remote file";
} else {
// local file
print "<script type=\"text/javascript\" src=\"jquery/1.11.3/jquery.min.js\"></script>";
print "local file";
}
Why it not work? I mean that script return "local file" when remote file exists and i wait that return "remote file". If i change url of Google with: "http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" then it work correctly. Where i mistake? And in case, how i can fix the script becouse it work Always? Thanks very much.
The curl function requires a few more parameters as you are trying to fetch from a https source.
function isurlok( $url ) {
/* You can download the cacert.pem from the web - search on Google */
$cacert='/path/to/cacert.pem';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_setopt( $ch, CURLOPT_USERAGENT, 'curl-fetchurl' );
if( parse_url( $url,PHP_URL_SCHEME )=='https' ){
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 1 );
curl_setopt( $curl, CURLOPT_CAINFO, realpath( $cacert ) );
}
curl_exec( $ch );
if( !curl_errno( $ch ) ) $info = curl_getinfo( $ch );
curl_close( $ch );
if ( isset( $info ) && array_key_exists('http_code',$info)) {
return $info['http_code'] == 200 ? true : false;
}
return false;
}