I have a huge list of domain names in the form of abcde.com
What I have to do is to check if the domains have a page otherwise I get the server not found message.
What is a code that will check this automatically and return开发者_高级运维 me something if there is a site ? I am familiar with PHP.
Thank you.
Something simple would be:
foreach ($domains as $domain) {
$html = file_get_contents('http://'.$domain);
if ($html) {
//do something with data
} else {
// page not found
}
}
If you have them in a txt file, with each line containing the domain name you could do this:
$file_handle = fopen("mydomains.txt", "r");
while (!feof($file_handle)) {
$domain = fgets($file_handle);
//use code above here
}
}
fclose($file_handle);
You can connect to each domain/hostname using cURL.
Example:
// I'm assuming one domain per line
$h = fopen("domains.txt", "r");
while (($host = preg_replace("/[\n\r]/", "", fgets($h))) !== false) {
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (curl_exec($ch) !== false) {
// code for domain/host with website
} else {
// code for domain/host without website
}
curl_close($ch);
}
精彩评论