-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_checker.php
More file actions
41 lines (34 loc) · 1.14 KB
/
url_checker.php
File metadata and controls
41 lines (34 loc) · 1.14 KB
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
<?php
ini_set("max_execution_time", 0);
$urls_path = "./urls.csv";
$result_path = "./result.csv";
$urls = file_get_contents($urls_path);
$urls = explode("\n", $urls);
if (count($urls) > 0){
$result = [];
foreach ($urls as $url) {
$url = mb_convert_encoding($url, "utf8");
//$url = "http://hogehugapiyo.com";
$context = stream_context_create(array(
'http' => array('ignore_errors' => true)
));
//$response = file_get_contents($url, false, $context);
//$status = $http_response_header[0];
$status = curl($url);
if ($status == 0)
$status = 404;
$result[] = "{$url} [{$status}]";
}
file_put_contents($result_path, implode("\n", $result));
echo count($result) . "件のURLを調べました";
}
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
return $statusCode;
}
?>