linkchecker
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
54
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
54
<?php
function getheaders($url,$format=0)
{
$url_info=parse_url($url);
$port = isset($url_info['port']) ? $url_info['port'] : 80;
if($fp=@fsockopen($url_info['host'], $port, $errno, $errstr, 30)){
if($fp)
{
$head = "HEAD ".@$url_info['path']."?".@$url_info['query']." HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";
fputs($fp, $head);
while(!feof($fp))
{
if($header=trim(fgets($fp, 1024)))
{
if($format == 1)
{
$key = array_shift(explode(':',$header));
// the first element is the http header type, such as HTTP 200 OK,
// it doesn't have a separate name, so we have to check for it.
if($key == $header)
{
$headers[] = $header;
}
else
{
$headers[$key]=substr($header,strlen($key)+2);
}
unset($key);
}
else
{
$headers[] = $header;
}
}
}
return $headers;
}
else
{
return false;
}
}else{
$headers[0] = '12007 The server name could not be resolved';
return $headers;
}
}
$array = array('http://www.phphulp.nl/','http://www.interrob.de','http://clubphp.phphulp.nl','http://www.phphulp.nl/faiejfeifjew.html');
for($i = 0;!empty($array[$i]);$i++){
$headers = getheaders($array[$i]);
echo $array[$i].' Melding: '.$headers[0].'<br />';
}
?>
function getheaders($url,$format=0)
{
$url_info=parse_url($url);
$port = isset($url_info['port']) ? $url_info['port'] : 80;
if($fp=@fsockopen($url_info['host'], $port, $errno, $errstr, 30)){
if($fp)
{
$head = "HEAD ".@$url_info['path']."?".@$url_info['query']." HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";
fputs($fp, $head);
while(!feof($fp))
{
if($header=trim(fgets($fp, 1024)))
{
if($format == 1)
{
$key = array_shift(explode(':',$header));
// the first element is the http header type, such as HTTP 200 OK,
// it doesn't have a separate name, so we have to check for it.
if($key == $header)
{
$headers[] = $header;
}
else
{
$headers[$key]=substr($header,strlen($key)+2);
}
unset($key);
}
else
{
$headers[] = $header;
}
}
}
return $headers;
}
else
{
return false;
}
}else{
$headers[0] = '12007 The server name could not be resolved';
return $headers;
}
}
$array = array('http://www.phphulp.nl/','http://www.interrob.de','http://clubphp.phphulp.nl','http://www.phphulp.nl/faiejfeifjew.html');
for($i = 0;!empty($array[$i]);$i++){
$headers = getheaders($array[$i]);
echo $array[$i].' Melding: '.$headers[0].'<br />';
}
?>