当前位置: 首页>>代码示例>>PHP>>正文


PHP P2Util::getP2UA方法代码示例

本文整理汇总了PHP中P2Util::getP2UA方法的典型用法代码示例。如果您正苦于以下问题:PHP P2Util::getP2UA方法的具体用法?PHP P2Util::getP2UA怎么用?PHP P2Util::getP2UA使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在P2Util的用法示例。


在下文中一共展示了P2Util::getP2UA方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * コンストラクタ
  *
  * @param string $url
  * @param string $destination
  * @param array $options
  * @param P2HttpCallback $onSuccess
  * @param P2HttpCallback $onFailure
  */
 public function __construct($url, $destination, array $options = null, P2HttpCallback $onSuccess = null, P2HttpCallback $onFailure = null)
 {
     global $_conf;
     if ($options === null) {
         $options = array();
     }
     if (!isset($options['connecttimeout'])) {
         $options['connecttimeout'] = $_conf['fsockopen_time_limit'];
     }
     if (!isset($options['timeout'])) {
         $options['timeout'] = $_conf['fsockopen_time_limit'] * 2;
     }
     if (!isset($options['compress'])) {
         $options['compress'] = true;
     }
     if (!isset($options['useragent'])) {
         $options['useragent'] = P2Util::getP2UA($withMonazilla = true);
     }
     if ($_conf['proxy_use'] && !isset($options['proxyhost']) && !empty($_conf['proxy_host'])) {
         $options['proxyhost'] = $_conf['proxy_host'];
         if (!empty($_conf['proxy_port']) && is_numeric($_conf['proxy_port'])) {
             $options['proxyport'] = (int) $_conf['proxy_port'];
         } elseif (strpos($_conf['proxy_host'], ':') === false) {
             $options['proxyport'] = 80;
         }
         /*
         $options['proxytype'] = HTTP_PROXY_HTTP;
         if (isset($_conf['proxy_type'])) {
             switch ($_conf['proxy_type']) {
             case 'http':   $options['proxytype'] = HTTP_PROXY_HTTP;   break;
             case 'socks4': $options['proxytype'] = HTTP_PROXY_SOCKS4; break;
             case 'socks5': $options['proxytype'] = HTTP_PROXY_SOCKS5; break;
             default:
                 if (is_numeric($options['proxytype'])) {
                     $options['proxytype'] = (int)$_conf['proxy_type'];
                 }
             }
         }
         
         if (!empty($_conf['proxy_auth'])) {
             $options['proxy_auth'] = $_conf['proxy_auth'];
             $options['proxyauthtype'] = HTTP_AUTH_BASIC;
             if (isset($_conf['proxy_auth_type'])) {
                 switch ($_conf['proxy_auth_type']) {
                 case 'basic':  $options['proxyauthtype'] = HTTP_AUTH_BASIC;  break;
                 case 'digest': $options['proxyauthtype'] = HTTP_AUTH_DIGEST; break;
                 case 'ntlm':   $options['proxyauthtype'] = HTTP_AUTH_NTLM;   break;
                 case 'gssneg': $options['proxyauthtype'] = HTTP_AUTH_GSSNEG; break;
                 case 'any':    $options['proxyauthtype'] = HTTP_AUTH_ANY;    break;
                 default:
                     if (is_numeric($options['proxytype'])) {
                         $options['proxyauthtype'] = (int)$_conf['proxy_auth_type'];
                     }
                 }
             }
         }
         */
     }
     if (!isset($options['lastmodified']) && file_exists($destination)) {
         $options['lastmodified'] = filemtime($destination);
     } else {
         FileCtl::mkdir_for($destination);
     }
     $this->_destination = $destination;
     $this->_permission = !empty($_conf['dl_perm']) ? $_conf['dl_perm'] : 0666;
     $this->_errorCode = self::E_NONE;
     $this->_errorInfo = '';
     $this->_onSuccess = $onSuccess;
     $this->_onFailure = $onFailure;
     $this->_next = null;
     parent::__construct($url, HttpRequest::METH_GET, $options);
 }
开发者ID:poppen,项目名称:p2,代码行数:81,代码来源:P2HttpExt.php

示例2: previewOne

 /**
  * >>1のみをプレビュー表示するためのHTMLを取得する(オンザフライに対応)
  *
  * @access  public
  * @return  string|false
  */
 function previewOne()
 {
     global $_conf, $ptitle_ht;
     if (!($this->host && $this->bbs && $this->key)) {
         return false;
     }
     $first_line = '';
     // ローカルdatから取得
     if (is_readable($this->keydat)) {
         $fd = fopen($this->keydat, "rb");
         $first_line = fgets($fd, 32800);
         fclose($fd);
     }
     if ($first_line) {
         // be.2ch.net ならEUC→SJIS変換
         if (P2Util::isHostBe2chNet($this->host)) {
             $first_line = mb_convert_encoding($first_line, 'SJIS-win', 'eucJP-win');
         }
         $first_datline = rtrim($first_line);
         if (strstr($first_datline, "<>")) {
             $datline_sepa = "<>";
         } else {
             $datline_sepa = ",";
             $this->dat_type = "2ch_old";
         }
         $d = explode($datline_sepa, $first_datline);
         $this->setTtitle($d[4]);
         // 便宜上
         if (!$this->readnum) {
             $this->readnum = 1;
         }
     }
     // ローカルdatなければオンラインから
     if (!$first_line) {
         $url = $this->getDatUrl($this->host, $this->bbs, $this->key);
         $purl = parse_url($url);
         $purl['query'] = isset($purl['query']) ? '?' . $purl['query'] : '';
         // プロキシ
         if ($_conf['proxy_use']) {
             $send_host = $_conf['proxy_host'];
             $send_port = $_conf['proxy_port'];
             $send_path = $url;
         } else {
             $send_host = $purl['host'];
             $send_port = isset($purl['port']) ? $purl['port'] : null;
             $send_path = $purl['path'] . $purl['query'];
         }
         // デフォルトを80
         !$send_port and $send_port = 80;
         $request = 'GET ' . $send_path . " HTTP/1.0\r\n";
         $request .= "Host: " . $purl['host'] . "\r\n";
         $request .= 'User-Agent: ' . P2Util::getP2UA($withMonazilla = true) . "\r\n";
         // $request .= "Range: bytes={$from_bytes}-\r\n";
         // Basic認証用のヘッダ
         if (isset($purl['user']) && isset($purl['pass'])) {
             $request .= "Authorization: Basic " . base64_encode($purl['user'] . ":" . $purl['pass']) . "\r\n";
         }
         $request .= "Connection: Close\r\n";
         $request .= "\r\n";
         // WEBサーバへ接続
         $fp = fsockopen($send_host, $send_port, $errno, $errstr, $_conf['fsockopen_time_limit']);
         if (!$fp) {
             P2Util::pushInfoHtml(sprintf('<p>サーバ接続エラー: %s (%s)<br>p2 info - %s に接続できませんでした。</p>', $errstr, $errno, P2View::tagA(P2Util::throughIme($url), hs($url), array('target' => $_conf['ext_win_target']))));
             $this->diedat = true;
             return false;
         }
         // HTTPリクエスト送信
         fputs($fp, $request);
         // HTTPヘッダレスポンスを取得する
         $h = $this->freadHttpHeader($fp);
         if ($h === false) {
             fclose($fp);
             $this->_pushInfoHtmlFreadHttpHeaderError($url);
             $this->diedat = true;
             return false;
         }
         // {{{ HTTPコードをチェック
         $code = $h['code'];
         // Partial Content
         if ($code == "200") {
             // OK。何もしない
             // 予期しないHTTPコード。なかったと判断する
         } else {
             fclose($fp);
             $this->previewOneNotFound();
             return false;
         }
         // }}}
         if (isset($h['headers']['Content-Length'])) {
             if (preg_match("/^([0-9]+)/", $h['headers']['Content-Length'], $matches)) {
                 $onbytes = $h['headers']['Content-Length'];
             }
         }
         // bodyを一行目だけ読む
//.........这里部分代码省略.........
开发者ID:poppen,项目名称:p2,代码行数:101,代码来源:ThreadRead.php


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