I'm trying to use the function fsockopen to check if exists a page. The problem i have, is that if I run the script from the shell of unix with a correct url, it works, however, if i use the script into a php-html page with the same url, it says the page doesn´t exist. Anybody knows the reason?????? I guess it could be a problem in the apache configuration.
The code of the script is the following:
class http {
function http_fopen($host, $path){
$fp = fsockopen($host,80,&$errno, &$errstr, 30);
if (!$fp){
return false;
}
fputs($fp,"GET $path HTTP/1.0\r\n");
fputs($fp,"Host: $host\r\n\r\n");
while(trim(fgets($fp,1024)) != ""); //removes HTTP headers
return $fp;
}
}
To use it i use:
$http = new http;
$fp = $http->http_fopen("www.yahoo.com","");
if (!$fp){
echo("missing page....."); //for example
}