remote-file-exists
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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);
}
}
}
?>
/*
* @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);
}
}
}
?>