Created
October 6, 2018 07:22
-
-
Save standa/1177165edf1c27d86c8630167ec4dad6 to your computer and use it in GitHub Desktop.
Multiple Domain Title Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
DomainChecker::checkDomains(); | |
/** | |
* @author standa <[email protected]> | |
* @version 2014-11-25 | |
*/ | |
class DomainChecker | |
{ | |
const CONTAINS = '<title>The no 1 page out there</title>'; | |
const LOG_FILE = 'DomainChecker.log'; | |
public static function checkDomains() | |
{ | |
$ok = array(); | |
$failed = array(); | |
$contains = self::CONTAINS; | |
foreach (explode(PHP_EOL, self::DOMAINS) as $domain) { | |
if (self::checkRedirect($domain, $contains)) { | |
$ok[] = $domain; | |
echo '.'; | |
} else { | |
$failed[] = $domain; | |
echo 'X'; | |
} | |
} | |
echo 'OK Domains: '.print_r($ok, true); | |
echo PHP_EOL.'Failed Domains: '.print_r($failed, true); | |
} | |
public static function checkRedirect($from, $contains) | |
{ | |
if (!self::startsWith($from, 'http://')) { | |
$from = 'http://'.$from; | |
} | |
$raw = file_get_contents($from); | |
return strpos($raw, $contains) !== false; | |
} | |
public static function startsWith($string, $starts) | |
{ | |
return substr($string, 0, strlen($starts)) == $starts; | |
} | |
public static function logMessage($msg) | |
{ | |
static $fp; | |
if (!is_resource($fp)) { | |
$fp = fopen(self::LOG_FILE, 'w'); | |
fwrite($fp, date(DATE_ISO8601).' '__METHOD__.'(): Logging start.'.PHP_EOL); | |
} | |
fwrite($fp, date(DATE_ISO8601).' '.trim($msg).PHP_EOL); | |
} | |
const DOMAINS = <<<EOD | |
www.domain.cz | |
www.domain.com | |
www.example.com | |
EOD; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment