AquAvia Posted September 26, 2008 Share Posted September 26, 2008 My ISP does not allow get_headers() in php 5.2.2 I need a work around for this: function ping($url) { $array=get_headers($url,1); return $array; } I am using this to see if a document excists on a remote server. I need back from headers: 1 - The response code: 404, 200, 300(+) 2 - The document type get headers works on my development server..... but not mu live server (ISP Problem) Anyone? Thanks, Mich Link to comment https://forums.phpfreaks.com/topic/125894-get_headers-php-522/ Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 <?php function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $URL); $contents = curl_exec($c); curl_close($c); if ($contents) return $contents; else return FALSE; } ?> Link to comment https://forums.phpfreaks.com/topic/125894-get_headers-php-522/#findComment-650999 Share on other sites More sharing options...
AquAvia Posted September 26, 2008 Author Share Posted September 26, 2008 <?php error_reporting(E_ALL); function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_HEADER, true); curl_setopt($c, CURLOPT_URL, $URL); $contents = curl_exec($c); curl_close($c); if ($contents) return $contents; else return FALSE; } $url = 'http://www.rca.com/documents/15311090_941_25.pdf'; $contents = curl_get_file_contents($url); print $contents; ?> This first gives me more or less what I want (the header) and then redirects me.... (big NO) ?? Link to comment https://forums.phpfreaks.com/topic/125894-get_headers-php-522/#findComment-651165 Share on other sites More sharing options...
Guardian-Mage Posted September 26, 2008 Share Posted September 26, 2008 Do you know where it is redirecting you? The url you put in? Also, put echo then exit statements in your script. Keep moving it down. It should help you pinpoint the code causing the redirection, because if no redirection occurs, then you move the echo statement down 1 line, and keep trying. It make take a while for larger scripts, but for something small like this, it works great. Also, please put your code in [ code ] tags Link to comment https://forums.phpfreaks.com/topic/125894-get_headers-php-522/#findComment-651173 Share on other sites More sharing options...
AquAvia Posted September 26, 2008 Author Share Posted September 26, 2008 Ok. I found the option that shows me the header only. Now I am at least half way.... <?php error_reporting(E_ALL); function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $URL); curl_setopt($c, CURLOPT_HEADER, true); curl_setopt($c, CURLOPT_NOBODY, true); $contents = curl_exec($c); curl_close($c); if ($contents) return $contents; else return FALSE; } $url = 'http://www.rca.com/documents/15311090_941_25.pdf'; $contents = curl_get_file_contents($url); print $contents; ?> This indeed gives me only the header. Unfortunately, this still does not the same as get_headers() where it would return an array and it was easy to extract document-type, etc. :'( Link to comment https://forums.phpfreaks.com/topic/125894-get_headers-php-522/#findComment-651183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.