Hi I have to check the URL is found or not.If the URL is available I need to load the URL
in iframe
.How can we do this?
My sample Code
<?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);
?>
In this case,If URL is available it's not loading/showing the iframe
Div
. Please suggest the better option for loading iframe
Try this code:
You can do the same thing without using cURL