Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.