Jump to content

is_html file on remote server


cooldude832

Recommended Posts

I'm trying to verify that a remote address inputted to my server is a valid html file.

 

I really shouldn't say html file, but I want it to be a document that isn't an image, js file, flash file, pdf etc.  just xhtml 

 

can I do file_get_content on the headers and verify its sending xhtml headers?

Link to comment
https://forums.phpfreaks.com/topic/86970-is_html-file-on-remote-server/
Share on other sites

You could usr curl to retrive the file then check the headers like this

 

<?php
$url="http://example.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//output buffer to stop page from being displayed
ob_start();
curl_exec($ch);
ob_end_clean();
$headers=curl_getinfo($ch);
curl_close($ch);
if($headers['content_type']=='text/html'){
echo 'Page is html';
}else{
echo 'Page is not html';
}
?>

 

Scott.

well I tried this, just wondering if I need a looser valid doc type list

<?php
		$valid_doc_types = array("Content-Type: text/html");
		$tempdata = get_headers($data['product_url']);
		if(is_array($tempdata)){
			if(!in_array($tempdata[8],$valid_doc_types)){
				$errors[] = "The field <b>product url</b> did not match our criteria of http://www.example.com";
			}
		}
?>

psedoed it

<?php
function get_headers($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//output buffer to stop page from being displayed
ob_start();
curl_exec($ch);
ob_end_clean();
$headers=curl_getinfo($ch);
curl_close($ch);
return $headers;
}
?>

for php 4

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.