• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_headers函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP get_headers函数的具体用法?PHP get_headers怎么用?PHP get_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_headers函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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');
        }
    }
}
开发者ID:AweKyle,项目名称:image_downloader,代码行数:35,代码来源:imgloader.php


示例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;
 }
开发者ID:relrod,项目名称:dagd,代码行数:30,代码来源:headers.php


示例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);
}
开发者ID:donwea,项目名称:nhap.org,代码行数:31,代码来源:key-check.php


示例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];
}
开发者ID:Jintha,项目名称:cama,代码行数:29,代码来源:functions.php


示例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("&amp;", "&", 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'];
    }
}
开发者ID:JohnTheBoss,项目名称:indadl,代码行数:41,代码来源:functions.php


示例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;
 }
开发者ID:smb,项目名称:laravel-gravatar,代码行数:7,代码来源:Gravatar.php


示例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));
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:10,代码来源:ZurmoTranslationServerUtilTest.php


示例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;
}
开发者ID:AmericanNumismaticSociety,项目名称:migration_scripts,代码行数:26,代码来源:process-csv.php


示例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;
}
开发者ID:robjcordes,项目名称:nexnewwp,代码行数:30,代码来源:wp_lightbox_utility_functions.php


示例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;
 }
开发者ID:chaobj001,项目名称:tt,代码行数:35,代码来源:class_rssfeed.php


示例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;
    }
}
开发者ID:ChristianWhiting,项目名称:photography-wordpress,代码行数:25,代码来源:download.php


示例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");
 }
开发者ID:archi-strasbourg,项目名称:aw2mw,代码行数:38,代码来源:ExportUserCommand.php


示例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;
 }
开发者ID:postman0,项目名称:1chan,代码行数:34,代码来源:preview.helper.php


示例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;
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:27,代码来源:transifex.php


示例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;
}
开发者ID:UCF,项目名称:Students-Theme,代码行数:25,代码来源:functions.php


示例16: add_uw_feed_enclosure_image

function add_uw_feed_enclosure_image()
{
    global $post;
    $thumbnailID = get_post_thumbnail_id($post->ID);
    if (!empty($thumbnailID)) {
        $url = wp_get_attachment_image_src($thumbnailID, 'rss');
        $url = $url[0];
        //$mime = get_post_mime_type($thumbnailID);  unneeded DB call to get mime type
        $img_headers = get_headers($url);
        foreach ($img_headers as $img_header) {
            $info = explode(" ", $img_header);
            if ($info[0] == 'Content-Length:') {
                $size = $info[1];
            } else {
                if ($info[0] == 'Content-Type:') {
                    $mime = $info[1];
                }
            }
        }
        ?>
        <enclosure url="<?php 
        echo $url;
        ?>
" type="<?php 
        echo $mime;
        ?>
" size="<?php 
        echo $size;
        ?>
" />
        <?php 
    }
}
开发者ID:uw-sop,项目名称:htdocs,代码行数:33,代码来源:prep-uw-rss2.php


示例17: get_data

 function get_data($start)
 {
     if ($_GET['q'] != '') {
         $url = 'https://www.googleapis.com/customsearch/v1element?prettyPrint=false&key=' . $this->key . '&cx=' . $this->cx . '&q=' . rawurlencode($_GET['q']) . '&start=' . $start;
         //$url2='https://www.googleapis.com/customsearch/v1?key='.$this->key.'&cx='.$this->cx.'&q='.rawurlencode($_GET['q']).'&start='.$start;
         $result = json_decode(@file_get_contents($url), true);
         foreach ($result['results'] as $data) {
             $c++;
             $result2[$c]['url'] = $data['formattedUrl'];
             $result2[$c]['des'] = $data['content'];
             $result2[$c]['title'] = $data['title'];
             $result2[$c]['link'] = $data['url'];
             $image_header = @get_headers($data['richSnippet']['cseThumbnail']['src']);
             if (strpos($headers[0], '404') === false) {
                 $result2[$c]['image'] = $data['richSnippet']['cseThumbnail']['src'];
                 //$data['richSnippet']['cseImage']['src'];
             }
         }
         /*foreach ($result['items'] as $data)
         		{
         			$c++;
         			$result2[$c]['url']=$data['htmlFormattedUrl'];
         			$result2[$c]['des']=$data['htmlSnippet'];
         			$result2[$c]['link']=$data['link'];
         			$image_header = @get_headers($data['pagemap']['cse_thumbnail'][0]['src']);
         			if(strpos($headers[0],'404') === false)
         			{
         				$result2[$c]['image']=$data['pagemap']['cse_thumbnail'][0]['src']; //$data['pagemap']['cse_image'][0]['src'];
         			}
         			$result2[$c]['title']=$data['htmlTitle'];
         		}*/
         return $result2;
     }
 }
开发者ID:h2dvnnet,项目名称:eLib,代码行数:34,代码来源:search.php


示例18: install

 public function install()
 {
     $e = get_headers(ERP_WS);
     if ($e[0] == 'HTTP/1.1 200 OK') {
         if ($this->isCurlInstalled() == false) {
             $this->_errors[] = $this->l('Error while installing the module. CURL Extension is not active on your server. Please contact your server administrator.');
             return false;
         }
         if (Shop::isFeatureActive()) {
             Shop::setContext(Shop::CONTEXT_ALL);
         }
         if (!Configuration::hasKey('ERP_ADMIN_PARENT_ORDERS_TAB_ID')) {
             Configuration::updateValue('ERP_ADMIN_PARENT_ORDERS_TAB_ID', Tab::getIdFromClassName('AdminParentOrders'));
         }
         if (parent::install() != false && $this->parseSQL('install.sql') != false && $this->installStockMvtReason() != false && $this->installErpTab() != false && $this->addTrashCategory() != false && $this->addOrderState($this->l('Order to the supplier')) != false && $this->registerHook('actionOrderStatusUpdate') != false && $this->registerHook('displayBackOfficeHeader') != false) {
             foreach ($this->field_name_configuration as $field_name => $param) {
                 Configuration::updateValue(Tools::strtoupper($field_name), $param['default']);
             }
             // load a licence if exits
             $this->loadLicenceIfExists();
             // save the first install date
             if (!Configuration::hasKey('ERP_FIRST_INSTALL_DATE') || Configuration::get('ERP_FIRST_INSTALL_DATE') == '' || Configuration::get('ERP_FIRST_INSTALL_DATE') == false) {
                 Configuration::updateValue('ERP_FIRST_INSTALL_DATE', date("Y-m-d H:i:s"));
             }
             return true;
         }
         return false;
     } else {
         $this->_errors[] = $this->l('Error while getting headers of WS ! Please contact the customer service.');
         return false;
     }
 }
开发者ID:prestamodule,项目名称:erpillicopresta,代码行数:32,代码来源:erpillicopresta.php


示例19: validate_full_url

/**
 ** Function: validate_full_url()
 ** Return: string containing validation error 
 **		-OR- FALSE if valid URL provided.
 **
 ** This function should be called to validate the user's input for
 ** a full URL (that will eventually be shortened). 
 **/
function validate_full_url()
{
    // Form for shortening URL submitted.  Validate input.
    if (empty(trim($_POST['full_url']))) {
        // No input provided. Create error message and display the form again.
        $error['full_url'] = "URL field is required.";
        return $error;
    }
    // If the user did not include display an error in the form.
    if (stripos($_POST['full_url'], "http://") === FALSE) {
        $error['full_url'] = "URLs must include 'http://' at the beginnning.";
        return $error;
    }
    $headers = get_headers($_POST['full_url'], 1);
    if ($headers === FALSE) {
        // Invalid URL or failure acessing the URL.  Create error and display form again.
        $error['full_url'] = "Invalid URL was provided.";
        return $error;
    }
    // $response array will include redirects and lots of extra info.
    // This will look nasty, if there is time I can clean this up.
    $rheaders = array_reverse($headers, TRUE);
    foreach ($rheaders as $key => $value) {
        // Find the first key that is numeric
        if (is_numeric($key)) {
            $response = substr($value, 9, 3);
            if (strcmp($response, "200") === FALSE) {
                $error['full_url'] = "Invalid URL was provided.";
                return $error;
            }
        }
    }
    // URL seems to be valid.
    return FALSE;
}
开发者ID:CBMcArthur,项目名称:URL_Shortener,代码行数:43,代码来源:functions.php


示例20: getGoogleImg

/**
 * Make a search from the Google Image API,
 * Browse the results,
 * Exclude "not found", "forbidden", "unavailable" status,
 * Return the path of the found image.
 * If not found, return an empty string.
 * If $thumb = true return the thumbnail image width, ortherwise return the full image width.
 * @param  string $search
 * @param  bool $thumb
 */
function getGoogleImg($search, $thumb = false)
{
    // Clean search string to remove special chars, and replace spaces with +
    $clean_str = cleanString($search, array(), '+');
    // If $thumb = true, look for the thumbnail url, otherwise look for the full image url
    $target = $thumb ? 'tbUrl' : 'url';
    // Construct the Google Image API query
    $query = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=' . urlencode($clean_str);
    // Get the result from query, returns a JSON object
    $json = file_get_contents($query);
    // Converts the JSON object in PHP array
    $results = json_decode($json, true);
    // If there are results from the query
    if (!empty($results["responseData"]["results"])) {
        // Browse each result from response and set it in $result
        foreach ($results["responseData"]["results"] as $result) {
            // Retrieve the HTTP headers
            $file_headers = @get_headers($result[$target]);
            // If HTTP headers don't contain status 403 (forbidden), 404 (not found) or 503 (unavailable)
            if (strpos($file_headers[0], '403') === false && strpos($file_headers[0], '404') === false && strpos($file_headers[0], '503') === false) {
                // Return the absolute image path (http://...) from result with $target as key
                return $result[$target];
            }
        }
    }
    // No image found, return an empty string
    return '';
}
开发者ID:vincenthib,项目名称:google_img,代码行数:38,代码来源:google_img.php



注:本文中的get_headers函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_height函数代码示例发布时间:2022-05-15
下一篇:
PHP get_header_textcolor函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap