cooldude832 Posted January 21, 2008 Share Posted January 21, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/86970-is_html-file-on-remote-server/ Share on other sites More sharing options...
ratcateme Posted January 21, 2008 Share Posted January 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86970-is_html-file-on-remote-server/#findComment-444691 Share on other sites More sharing options...
cooldude832 Posted January 21, 2008 Author Share Posted January 21, 2008 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86970-is_html-file-on-remote-server/#findComment-444692 Share on other sites More sharing options...
cooldude832 Posted January 21, 2008 Author Share Posted January 21, 2008 after I realize get_headers is php 5 and i'm on a 4 server... Quote Link to comment https://forums.phpfreaks.com/topic/86970-is_html-file-on-remote-server/#findComment-444695 Share on other sites More sharing options...
cooldude832 Posted January 21, 2008 Author Share Posted January 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86970-is_html-file-on-remote-server/#findComment-444698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.