Voting

: zero plus eight?
(Example: nine)

The Note You're Voting On

jack at jtr dot de
21 years ago
Here is a function for testing a website/URI for availability:

<?php
/*
* @return boolean
* @param string $link
* @desc ?berpr?ft die angegeben URL auf Erreichbarkeit (HTTP-Code: 200)
*/
function url_validate( $link )
{
$url_parts = @parse_url( $link );

if ( empty(
$url_parts["host"] ) ) return( false );

if ( !empty(
$url_parts["path"] ) )
{
$documentpath = $url_parts["path"];
}
else
{
$documentpath = "/";
}

if ( !empty(
$url_parts["query"] ) )
{
$documentpath .= "?" . $url_parts["query"];
}

$host = $url_parts["host"];
$port = $url_parts["port"];
// Now (HTTP-)GET $documentpath at $host";

if (empty( $port ) ) $port = "80";
$socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
if (!
$socket)
{
return(
false);
}
else
{
fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
$http_response = fgets( $socket, 22 );

if (
ereg("200 OK", $http_response, $regs ) )
{
return(
true);
fclose( $socket );
} else
{
// echo "HTTP-Response: $http_response<br>";
return(false);
}
}
}
?>

<< Back to user notes page

To Top