Forum Moderators: coopster
if($sock=fsockopen('something.net',80))
{
fputs($sock, "HEAD /something.html HTTP/1.0\r\n\r\n");
while(!feof($sock))
{
echo fgets($sock);
}
}
This will echo 'HTTP/1.0 404 Requested URL not found' if the page does not exist or 'HTTP/1.0 200 OK' if the page does exist.
[edited by: coopster at 5:13 pm (utc) on Dec. 13, 2006]
[edit reason] removed url [/edit]
1) i have to check if the HOST exists.
2) in case the url has a page or path, i also need to check if they exist.
3) i need to grab the page's meta tags into an array.
For all that i am doing this thanks to the code provided above:
$h = fsockopen('somehost.com',80);
if($h) {
$fp = file_get_contents('http://somehost.com/some.html');
if($fp) {
$tags = get_meta_tags('http://somehost.com/some.html');
print_r($tags);
}
}
----Is that enough, or maybe it could get optimized? Thanks again, Andres.
$h = fsockopen('somehost.com',80)
or die();
$fp = file_get_contents('http://somehost.com/some.html')
or die();
$tags = get_meta_tags('http://somehost.com/some.html');
print_r($tags);
Maybe someone with more experience can confirm whether this is more efficient or not.
If it is more efficient is by an insignificant amount; it wouldn't even be noticeable, IMO.