function checkURLs($base, $url, $ref) { global $checked; global $x; global $out; $response = get_headers_curl($url); $checked[] = $url; if ($response[0] == 'HTTP/1.1 200 OK' || $response[0] == 'HTTP/1.0 200 OK') { $out['passed'][] = $url; $file = file_get_contents($url); if (substr(parse_url($url, PHP_URL_PATH), -2) != 'js') { // jquery.js has links to /a by using the below syntax, this stops it from happening. $hrefs1 = explode('href="', $file); array_shift($hrefs1); $hrefs2 = explode("href='", $file); array_shift($hrefs2); $hrefs3 = explode('src="', $file); array_shift($hrefs3); $hrefs4 = explode("src='", $file); array_shift($hrefs4); $hrefs = array_merge($hrefs1, $hrefs2, $hrefs3, $hrefs4); foreach ($hrefs as $href) { if (strpos($href, '"')) { $end = strpos($href, '"'); } if (strpos($href, "'")) { $end = strpos($href, "'") < $end ? strpos($href, "'") : $end; } $newURL = substr($href, 0, $end); if (empty($newURL)) { $newURL = $end1 . ' ' . $end2 . ' ' . substr($href, 0, 10); } if (substr($newURL, 0, 1) == '/' && substr($newURL, 0, 2) != '//') { $newURL = $base . $newURL; } if (substr($newURL, 0, 1) != '#' && substr($newURL, 0, 2) != '//') { $urls[] = $newURL; } } } if (isset($urls)) { foreach ($urls as $ourURL) { if (substr($ourURL, 0, strlen($base)) == $base && !in_array($ourURL, $checked)) { $x++; if ($x % 20 == 0) { echo $x . "\n"; } checkURLs($base, $ourURL, $url); } } } } elseif ($response[0] == 'HTTP/1.1 301 Moved Permanently' || $response[0] == 'HTTP/1.0 301 Moved Permanently') { $out['redirected'][] = $url; } else { echo colourise('Didn\'t get 200: ' . $response[0] . ' for ' . $url . ' from ' . $ref . "\n", 'fail'); $out['failed'][] = colourise('Didn\'t get 200: ' . $response[0] . ' for ' . $url . ' from ' . $ref . "\n", 'fail'); } }
function getBattlelogId($battlelogName) { // check for bf4 entry $url = "http://api.bf4stats.com/api/playerInfo?plat=pc&name={$battlelogName}"; ini_set('default_socket_timeout', 10); $headers = get_headers_curl($url); if ($headers) { if (stripos($headers[0], '40') !== false || stripos($headers[0], '50') !== false) { $result = array('error' => true, 'message' => 'Player not found, or BF Stats server down.'); } else { $json = get_bf4db_dump($url); $data = json_decode($json); $personaId = $data->player->id; if (!containsNumbers($data->player->id)) { $result = array('error' => true, 'message' => 'Player not found, or BF Stats server down.'); } else { $result = array('error' => false, 'id' => $personaId); } } return $result; } return $result = array('error' => true, 'message' => 'Timed out. Probably a 404.'); }
function is_valid_url($url) { $url = @parse_url($url); if (!$url) { return false; } $url = array_map('trim', $url); $url['port'] = !isset($url['port']) ? 80 : (int) $url['port']; $path = isset($url['path']) ? $url['path'] : ''; if ($path == '') { $path = '/'; } $path .= isset($url['query']) ? "?{$url['query']}" : ''; if (isset($url['host']) and $url['host'] != gethostbyname($url['host'])) { if (PHP_VERSION >= 5) { $headers = get_headers_curl("{$url['scheme']}://{$url['host']}:{$url['port']}{$path}"); //print_r($headers); } $headers = is_array($headers) ? implode("\n", $headers) : $headers; preg_match_all('#^HTTP/.*\\s+[0-9]+\\s#i', $headers, $match); $tmp = explode(' ', $match[0][0]); //print_r($tmp); $code = array(200, 301, 302); if (in_array($tmp[1], $code)) { return true; } } return false; }