View Single Post
  #2 (permalink)  
Old 02-21-08, 09:56 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
I used a small script that attempts to connect to the website through a socket. I simply set the default timeout of the access-attempt to 10 seconds, and when the timeout was reached, I stated the url as invalid:
PHP Code:

/**
 * Checks if the entered url links to a valid website. 
 * A valid website is one that responses within a timelimit of <code>$seconds</code>
 *
 * @param string The url that need to be checked
 * @param integer The number of seconds before a timeout occurs. default=10
 * @return boolean True if the website responded, false otherwise
*/
function isValidWebsite ($url$seconds=NULL) {
  
$realUrl preg_replace ('#https?:\/{2}([^\/\\]+).*?#s''\\1'$url);
  
$seconds is_null ($seconds)? 10 $seconds;
  return 
fsockopen ($realUrl80$errNo$errStr$seconds);

There might be some easier ways, but this one has worked fine for me
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote