Advertisement
andreimunteanu

PHPAndrei

Nov 25th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php
  2.  
  3. function isDomainAvailable($domain)
  4.        {
  5.                //check, if a valid url is provided
  6.                if(!filter_var($domain, FILTER_VALIDATE_URL))
  7.                {
  8.                        return false;
  9.                }
  10.  
  11.                //initialize curl
  12.                $curlInit = curl_init($domain);
  13.                curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
  14.                curl_setopt($curlInit,CURLOPT_HEADER,true);
  15.                curl_setopt($curlInit,CURLOPT_NOBODY,true);
  16.                curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
  17.  
  18.                //get answer
  19.                $response = curl_exec($curlInit);
  20.  
  21.                curl_close($curlInit);
  22.  
  23.                if ($response) return true;
  24.  
  25.                return false;
  26.      }
  27.  
  28.  
  29.  
  30. $file = fopen("sites.txt", "r");
  31. $sites = array();
  32.  
  33. while (!feof($file)) {
  34.    $sites[] = fgets($file);
  35. }
  36.  
  37. fclose($file);
  38.  
  39. foreach ($sites as $value) {
  40.  
  41.    echo "$value <br>";
  42.  
  43.   if(!strstr($value, "http://") && !strstr($value, "https://"))
  44.     {
  45.       $value = "http://" . $value;
  46.     }
  47.        if (isDomainAvailable($value))
  48.        {
  49.                header("Location: $value");
  50.              
  51.        }
  52.        else
  53.        {
  54.                echo "Woops, nothing found there. </br>";
  55.        }
  56.      
  57.     }
  58.  
  59.    
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement