Page 1 of 1
Help..How to find a host live or not before using header()
Posted: Tue Apr 17, 2007 12:11 pm
by anirbanb2004
Hi,
Please help me if anybody can,
I am using header('Location:$host') to redirect now how can I determine first that wheather the $host is live or not?Is there any way to redirect to a custom failure page if $host is not accesible?
Posted: Tue Apr 17, 2007 12:55 pm
by Charles256
Code: Select all
if(isset($host))
{
//blah
}
else
{
// other bah
}
?
Posted: Tue Apr 17, 2007 1:00 pm
by Chris Corbyn
I think you're referring to determining if the address is physically accessible. Use:
Code: Select all
if ($sock = fsockopen($host, 80, 10, $errno, $errstr))
{
fclose($sock);
//ok
}
Posted: Tue Apr 17, 2007 1:20 pm
by anirbanb2004
what would be errno and errstr??
Posted: Tue Apr 17, 2007 1:27 pm
by RobertGonzalez
Think really hard about that question... errno (error number perhaps) and errstr (error string, message, perhaps)...
The manual has a great deal of information about how functions work.

Posted: Tue Apr 17, 2007 1:27 pm
by John Cartwright
It's a bit confusing at first, but if you look at the manual you'll notice that you arn't passing those variables to the function, they are there to provide more detailed output if fsockopen() fails.
Posted: Tue Apr 17, 2007 2:48 pm
by anirbanb2004
Code doesn't run better to say perhaps I couldn't make it use.I am to check address like
http://59.93.193.52:8080 is alive or not.