本文整理汇总了PHP中get_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP get_headers函数的具体用法?PHP get_headers怎么用?PHP get_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_image
function get_image()
{
$id = rand(101, 585295);
//id изображений на сайте начинаются со 101. 585295 далеко не последнее изображение, так что можно смело писать цифру побольше
$url = "http://nuclear-wallpapers.ru.com/download.php?id=" . $id . "&width=1366&height=768";
/*
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
$res = curl_exec($ch);
curl_close($ch);
*/
$img = "http://white-wallpapers.ru/image/" . $id . "-1366-768-nuclear-wallpapers.ru.com.jpg";
/*
*Эту проверку делал для себя, на случай отсутствия интернета..
*/
$check = get_headers($url);
if ($check[0] !== 'HTTP/1.1 200 OK') {
//проверяем, нормальный ли заголовок нам возвращается
$dir = opendir('/mnt/trash/dl/wllpprs/');
while (false !== ($file = readdir($dir))) {
$images[] = $file;
}
shuffle($images);
$img = '/mnt/trash/dl/wllpprs/' . $images[0];
copy($img, '/home/nikolay/walls/wall.jpg');
} else {
if (!getimagesize($img)) {
//бывает, что попадается битое изображение, так что проверяется его размер
get_image();
} else {
copy('/home/nikolay/walls/wall.jpg', '/home/nikolay/walls/old_wall.jpg');
copy($img, '/home/nikolay/walls/wall.jpg');
}
}
}
示例2: render
public function render()
{
$headers = array();
$response = '';
if (count($this->route_matches) > 1) {
$site = $this->route_matches[1];
if (!preg_match('@^https?://@i', $site)) {
$site = 'http://' . $site;
}
$headers = @get_headers($site);
if (!$headers) {
error400('Headers could not be retrieved for that domain.');
return;
}
foreach ($headers as $header) {
$response .= htmlspecialchars($header . "\n");
}
} else {
$headers = getallheaders();
foreach ($headers as $key => $value) {
if (server_or_default('HTTP_X_DAGD_PROXY') == "1") {
if (strpos($key, 'X-Forwarded-') === 0 || $key == 'X-DaGd-Proxy') {
continue;
}
}
$response .= htmlspecialchars($key . ': ' . $value . "\n");
}
}
return $response;
}
示例3: lrss_is_site_available
function lrss_is_site_available($url)
{
//check, if a valid url is provided
if (!filter_var($url, FILTER_VALIDATE_URL)) {
return FALSE;
}
if (!function_exists('curl_init') && function_exists('get_headers')) {
$headers = get_headers($url, 1);
if ($headers[0] == 'HTTP/1.1 200 OK') {
return TRUE;
} else {
return FALSE;
}
} else {
if (function_exists('curl_init') && !function_exists('get_headers')) {
return FALSE;
}
}
$handle = curl_init(urldecode($url));
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 0.5);
curl_setopt($handle, CURLOPT_TIMEOUT, 1);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if ($httpCode >= 200 && $httpCode < 400) {
return TRUE;
} else {
return FALSE;
}
curl_close($handle);
}
示例4: FileSizeOf
function FileSizeOf($link)
{
if (strpos($link, get_option('siteurl')) === false) {
$link = str_replace(' ', '%20', $link);
if (function_exists('get_headers')) {
$headers = @get_headers($link, 1);
if ($headers['Content-Length'] == '') {
return;
}
$size = $headers['Content-Length'];
} else {
$file = @file_get_contents($link);
if ($file == false) {
return;
}
$size = strlen($file);
}
} else {
$file = ABSPATH . 'wp-content/plugins/downloads-manager/upload/' . basename($link);
$size = @filesize($file);
}
$i = 0;
$type = array("B", "KB", "MB", "GB");
while ($size / 1024 > 1) {
$size = $size / 1024;
$i++;
}
return substr($size, 0, strpos($size, '.') + 3) . $type[$i];
}
示例5: get_final_url
/**
* Follows redirects of a url and returns the final one.
*
* @param string $url
* @param int $timeout
* @return mixed
*/
function get_final_url($url, $timeout = 120)
{
$url = str_replace("&", "&", urldecode(trim($url)));
$cookie = tempnam("/tmp", "CURLCOOKIE");
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$content = curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);
if ($response['http_code'] == 301 || $response['http_code'] == 302) {
ini_set("user_agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1");
$headers = get_headers($response['url']);
$location = "";
foreach ($headers as $value) {
if (substr(strtolower($value), 0, 9) == "location:") {
return get_final_url(trim(substr($value, 9, strlen($value))));
}
}
}
if (preg_match("/window\\.location\\.replace\\('(.*)'\\)/i", $content, $value) || preg_match("/window\\.location\\=\"(.*)\"/i", $content, $value)) {
return get_final_url($value[1]);
} else {
return $response['url'];
}
}
示例6: exists
public function exists($email)
{
$this->setDefaultImage('404');
$url = $this->buildGravatarURL($email);
$headers = get_headers($url, 1);
return strpos($headers[0], '200') ? true : false;
}
示例7: testGetPoFileUrl
/**
* @depends testGetAvailableLanguages
*/
public function testGetPoFileUrl()
{
$url = ZurmoTranslationServerUtil::getPoFileUrl('de');
$headers = get_headers($url);
list($version, $status_code, $msg) = explode(' ', $headers[0], 3);
$this->assertEquals(200, intval($status_code));
}
示例8: check_uri
function check_uri($uri)
{
global $coinTypes;
//if the URI is in the array
if (array_key_exists($uri, $coinTypes)) {
if ($coinTypes[$uri] == true) {
echo "Found {$uri}\n";
$valid = true;
} else {
echo "Did not find {$uri}\n";
$valid = false;
}
} else {
$file_headers = @get_headers($uri);
if ($file_headers[0] == 'HTTP/1.1 200 OK') {
echo "Matched new {$uri}\n";
$coinTypes[$uri] = true;
$valid = true;
} else {
echo "Did not find {$uri}\n";
$coinTypes[$uri] = false;
$valid = false;
}
}
return $valid;
}
示例9: wp_lightbox_is_valid_url
function wp_lightbox_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("{$url['scheme']}://{$url['host']}:{$url['port']}{$path}");
} else {
$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
if (!$fp) {
return false;
}
fputs($fp, "HEAD {$path} HTTP/1.1\r\nHost: {$url['host']}\r\n\r\n");
$headers = fread($fp, 128);
fclose($fp);
}
$headers = is_array($headers) ? implode("\n", $headers) : $headers;
return (bool) preg_match('#^HTTP/.*\\s+[(200|301|302)]+\\s#i', $headers);
}
return false;
}
示例10: check_if_requires_auth
public function check_if_requires_auth()
{
global $C;
$result = FALSE;
if ($this->has_curl) {
$ch = curl_init();
curl_setopt_array($ch, array(CURLOPT_AUTOREFERER => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5, CURLOPT_MAXREDIRS => 3, CURLOPT_REFERER => $C->SITE_URL, CURLOPT_URL => $this->url));
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
if (!empty($this->userpwd)) {
curl_setopt($ch, CURLOPT_USERPWD, $this->userpwd);
}
$result = curl_exec($ch);
$result = trim($result);
curl_close($ch);
} elseif (function_exists('get_headers')) {
$result = get_headers($this->url);
$result = $result ? implode("\n", $result) : FALSE;
}
if (!$result || empty($result)) {
return FALSE;
}
if (preg_match('/(^|\\n|\\r)(\\s)*HTTP\\/[0-9.]+(\\s)+401(\\s)+Authorization(\\s)+Required(\\s)*($|\\n|\\r)/is', $result)) {
if (preg_match('/(^|\\n|\\r)(\\s)*WWW\\-Authenticate\\:\\s([a-z0-9-]+)/i', $result)) {
return TRUE;
}
}
if (preg_match('/(^|\\n|\\r)(\\s)*HTTP\\/[0-9.]+(\\s)+401(\\s)+Unauthorized(\\s)*($|\\n|\\r)/is', $result)) {
if (preg_match('/(^|\\n|\\r)(\\s)*WWW\\-Authenticate\\:\\s([a-z0-9-]+)/i', $result)) {
return TRUE;
}
$this->error = TRUE;
return FALSE;
}
return FALSE;
}
示例11: retrieve_remote_file_size
function retrieve_remote_file_size($url)
{
if (function_exists('curl_version')) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
return $size;
} elseif (function_exists('get_headers')) {
$remote_header = get_headers($file_url, true);
if ($remote_header !== false) {
$remote_header = array_change_key_case($remote_header);
if (!empty($remote_header['content-length'])) {
$filesize = (double) $remote_header['content-length'];
}
}
return isset($filesize) ? $filesize : false;
} else {
return false;
}
}
示例12: execute
/**
* Execute command
*
* @param InputInterface $input Input
* @param OutputInterface $output Output
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::setup($input, $output);
$id = $input->getArgument('id');
$user = $this->u->getArrayInfosFromUtilisateur($id);
$pageName = 'Utilisateur:' . $user['prenom'] . ' ' . $user['nom'];
$output->writeln('<info>Exporting "' . $pageName . '"…</info>');
$content = '';
$this->loginAsAdmin();
$this->deletePage($pageName);
//Login as user
$this->login($user['prenom'] . ' ' . $user['nom']);
$oldPath = 'http://www.archi-wiki.org/images/avatar/' . $id . '/original.jpg';
$headers = get_headers($oldPath, 1);
if ($headers[0] == 'HTTP/1.1 200 OK') {
$filename = 'Avatar ' . $user['prenom'] . ' ' . $user['nom'] . '.jpg';
$params = array('filename' => $filename, 'token' => $this->api->getToken('edit'), 'url' => $oldPath);
if ($input->getOption('force')) {
$params['ignorewarnings'] = true;
}
$output->writeln('<info>Exporting "File:' . $filename . '"…</info>');
$this->api->postRequest(new Api\SimpleRequest('upload', $params, array()));
} else {
$filename = '';
}
$this->savePage($pageName, '{{Infobox utilisateur
|site=' . $user['urlSiteWeb'] . '
|avatar=' . $filename . '
}}', "Profil importé depuis Archi-Wiki");
}
示例13: upload
/**
* Загрузка:
*/
public function upload($url)
{
$kvs = KVS::getInstance();
if ($kvs->exists(__CLASS__, $url)) {
return $kvs->get(__CLASS__, $url);
}
$data = @get_headers($url, 1);
if (in_array($data['Content-Type'], array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'))) {
$tm = tempnam('/tmp', 'img');
$nam = md5(uniqid('', true));
$dir = substr($nam, 0, 1);
$im = fopen($url, 'r');
$fp = fopen($tm, 'w');
$start = time();
while (!feof($im) && time() - $start < 5) {
fputs($fp, fgets($im, 24));
}
fclose($im);
fclose($fp);
if (time() - $start > 5) {
return false;
}
self::createThumbnail($tm, UPLOAD_PATH . '/news/' . $dir . '/' . $nam . '.png');
$p = '/uploads/news/' . $dir . '/' . $nam . '.png';
@unlink(tm);
$kvs->set(__CLASS__, $url, null, '/uploads/news/' . $dir . '/' . $nam . '.png');
$kvs->expire(__CLASS__, $url, null, 60 * 60 * 24 * 30);
return $p;
}
return false;
}
示例14: downloadLangInstaller
public function downloadLangInstaller($resources, $language)
{
// check tmp
if ($warning = $this->app->zlfw->path->checkSystemPaths()) {
$response['success'] = false;
$response['errors'][] = $warning;
echo json_encode($response);
jexit();
}
$this->_initCheck();
// set default file name
$filename = $language . '.' . (count($resources) > 1 ? 'language_pack' : $resources[0]) . '.zip';
// set url
$url = self::$apiUrl . 'getLangInstaller&resources=' . implode(',', $resources) . '&language=' . $language;
// attempt to override file name with one from header response
$headers = get_headers($url, 1);
if (isset($headers['Content-Disposition'])) {
if (preg_match('/name="(?P<filename>.+?)"/', $headers['Content-Disposition'], $matches)) {
$filename = $matches['filename'];
}
}
// set file destination
$file = JPath::clean(JPATH_SITE . '/tmp/' . $filename);
// download
$result = $this->app->zl->extensions->download($url, $file);
return $file;
}
示例15: get_remote_menu
function get_remote_menu($menu_name)
{
global $wp_customize;
$customizing = isset($wp_customize);
$result_name = $menu_name . '_json';
$result = get_transient($result_name);
if (false === $result || $customizing) {
$opts = array('http' => array('timeout' => 15));
$context = stream_context_create($opts);
$file_location = get_theme_mod_or_default($menu_name . '_feed');
if (empty($file_location)) {
return;
}
$headers = get_headers($file_location);
$response_code = substr($headers[0], 9, 3);
if ($response_code !== '200') {
return;
}
$result = json_decode(file_get_contents($file_location, false, $context));
if (!$customizing) {
set_transient($result_name, $result, 60 * 60 * 24);
}
}
return $result;
}