Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用PHP检查URL是否可用。如果URL可用,请加载iframe_Javascript_Php_Iframe - Fatal编程技术网

Javascript 使用PHP检查URL是否可用。如果URL可用,请加载iframe

Javascript 使用PHP检查URL是否可用。如果URL可用,请加载iframe,javascript,php,iframe,Javascript,Php,Iframe,您好,我必须检查URL是否找到。如果URL可用,我需要在iframe中加载URL。我们怎么做 我的示例代码 <?php $url = 'http://example.com/t/urlname'; $handle = curl_init($url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); /* Get the HTML or whatever is linked in $url. */ $response

您好,我必须检查URL是否找到。如果URL可用,我需要在
iframe
中加载
URL
。我们怎么做

我的示例代码

<?php
    $url = 'http://example.com/t/urlname';
    $handle = curl_init($url);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);

/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
    /* Handle 404 here. */
    echo "Url Not found";

} else { ?>

                    <div id="iframe-comments">
            <iframe  src="<?php echo $url; ?>" scrolling="no" style="width: 800px; height: 800px;"> 
                </iframe>

</div>
<?php 
}

curl_close($handle);
    ?>

请尝试以下代码:

不使用cURL也可以做同样的事情

$url = 'http://thedemon.in';
$file_headers = @get_headers($url);

if($file_headers[0] == 'HTTP/1.1 200 OK') {

    ?>
   <div id="iframe-comments">
        <iframe  src="<?php echo $url; ?>" scrolling="no" style="width: 300px; height: 300px;"> </iframe>
    </div>
    <?php
}
else {
     echo "Url Not found";
}
$url='1!'http://thedemon.in';
$file\u headers=@get\u headers($url);
如果($file_headers[0]='HTTP/1.1 200 OK'){
?>

那么呢?您需要检查curl是否成功。例如,
if($response==false){die(curl\u error($handle))}
。如果请求从未从前门发出,http代码可能根本不可用。