/** * UtilityTest::testGetHeaderFromUrl() * * @covers Utility::getHeaderFromUrl * @return void */ public function testGetHeaderFromUrl() { $res = Utility::getHeaderFromUrl('http://www.spiegel.de'); $this->assertTrue(is_array($res) && count($res) > 1); //$this->assertEquals('HTTP/1.0 200 OK', $res[0]); }
/** * @static * 2009-12-26 ms */ public static function getHeaderFromUrl($url) { return Utility::getHeaderFromUrl($url); }
/** * checks if a url is valid * @param string url * 2009-02-27 ms */ public function _validUrl($url = null) { App::import('Component', 'Tools.Common'); $headers = Utility::getHeaderFromUrl($url); if ($headers !== false) { $headers = implode("\n", $headers); return (bool) preg_match('#^HTTP/.*\\s+[(200|301|302)]+\\s#i', $headers) && !(bool) preg_match('#^HTTP/.*\\s+[(404|999)]+\\s#i', $headers); } return false; }
/** * Checks if a url is valid * * @param string url * @return bool Success */ protected function _validUrl($url) { $headers = Utility::getHeaderFromUrl($url); if ($headers === false) { return false; } $headers = implode("\n", $headers); $protocol = mb_strpos($url, 'https://') === 0 ? 'HTTP' : 'HTTP'; if (!preg_match('#^' . $protocol . '/.*?\\s+[(200|301|302)]+\\s#i', $headers)) { return false; } if (preg_match('#^' . $protocol . '/.*?\\s+[(404|999)]+\\s#i', $headers)) { return false; } return true; }