Help..How to find a host live or not before using header()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anirbanb2004
Forum Newbie
Posts: 23
Joined: Sun Oct 15, 2006 4:21 pm

Help..How to find a host live or not before using header()

Post 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?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

Code: Select all

if(isset($host))
{
  //blah
}
else
{
  // other bah
}
?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
}
anirbanb2004
Forum Newbie
Posts: 23
Joined: Sun Oct 15, 2006 4:21 pm

Post by anirbanb2004 »

what would be errno and errstr??
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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. ;)
Last edited by RobertGonzalez on Tue Apr 17, 2007 1:29 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
anirbanb2004
Forum Newbie
Posts: 23
Joined: Sun Oct 15, 2006 4:21 pm

Post 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.
Post Reply