本文整理汇总了PHP中Http::buildCookieHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::buildCookieHeader方法的具体用法?PHP Http::buildCookieHeader怎么用?PHP Http::buildCookieHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Http
的用法示例。
在下文中一共展示了Http::buildCookieHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
/**
*
* @param mixed $url
* @param mixed $args
* @return
*/
public function request($url, $args = array())
{
$defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array());
$args = Http::build_args($args, $defaults);
// Get User Agent
if (isset($args['headers']['User-Agent'])) {
$args['user-agent'] = $args['headers']['User-Agent'];
unset($args['headers']['User-Agent']);
} elseif (isset($args['headers']['user-agent'])) {
$args['user-agent'] = $args['headers']['user-agent'];
unset($args['headers']['user-agent']);
}
// Get Referer
if (isset($args['headers']['Referer'])) {
$args['referer'] = $args['headers']['Referer'];
unset($args['headers']['Referer']);
} elseif (isset($args['headers']['referer'])) {
$args['referer'] = $args['headers']['referer'];
unset($args['headers']['referer']);
}
// Construct Cookie: header if any cookies are set.
Http::buildCookieHeader($args);
$handle = curl_init();
/*
// No Proxy setting so proxy be omitted
// cURL offers really easy proxy support.
$proxy = new Http_proxy();
if( $proxy->is_enabled() and $proxy->send_through_proxy( $url ) )
{
curl_setopt( $handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );
curl_setopt( $handle, CURLOPT_PROXY, $proxy->host() );
curl_setopt( $handle, CURLOPT_PROXYPORT, $proxy->port() );
if( $proxy->use_authentication() )
{
curl_setopt( $handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY );
curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() );
}
}
*/
$is_local = isset($args['local']) and $args['local'];
$ssl_verify = isset($args['sslverify']) and $args['sslverify'];
// CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since
// a value of 0 will allow an unlimited timeout.
$timeout = (int) ceil($args['timeout']);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($handle, CURLOPT_TIMEOUT, $timeout);
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify === true ? 2 : false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify);
curl_setopt($handle, CURLOPT_CAINFO, $args['sslcertificates']);
curl_setopt($handle, CURLOPT_USERAGENT, $args['user-agent']);
// Add Curl referer if not empty
if (!is_null($args['referer']) or !empty($args['referer'])) {
curl_setopt($handle, CURLOPT_AUTOREFERER, true);
curl_setopt($handle, CURLOPT_REFERER, $args['referer']);
}
// The option doesn't work with safe mode or when open_basedir is set, and there's a
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, false);
if (defined('CURLOPT_PROTOCOLS')) {
// PHP 5.2.10 / cURL 7.19.4
curl_setopt($handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
}
switch ($args['method']) {
case 'HEAD':
curl_setopt($handle, CURLOPT_NOBODY, true);
break;
case 'POST':
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $args['body']);
break;
case 'PUT':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($handle, CURLOPT_POSTFIELDS, $args['body']);
break;
default:
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, $args['method']);
if (!is_null($args['body'])) {
curl_setopt($handle, CURLOPT_POSTFIELDS, $args['body']);
}
break;
}
if ($args['blocking'] === true) {
curl_setopt($handle, CURLOPT_HEADERFUNCTION, array($this, 'stream_headers'));
curl_setopt($handle, CURLOPT_WRITEFUNCTION, array($this, 'stream_body'));
}
curl_setopt($handle, CURLOPT_HEADER, false);
if (isset($args['limit_response_size'])) {
$this->max_body_length = intval($args['limit_response_size']);
} else {
$this->max_body_length = false;
}
//.........这里部分代码省略.........
示例2: request
/**
*
* @param mixed $url
* @param mixed $args
* @return
*/
private function request($url, $args)
{
$defaults = array('method' => 'GET', 'timeout' => 10, 'redirection' => 5, 'requested' => 0, 'httpversion' => 1.0, 'user-agent' => 'NUKEVIET CMS ' . $this->site_config['version'] . '. Developed by VINADES. Url: http://nukeviet.vn. Code: ' . md5($this->site_config['sitekey']), 'referer' => null, 'reject_unsafe_urls' => false, 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'sslcertificates' => $this->root_dir . '/includes/certificates/ca-bundle.crt', 'stream' => false, 'filename' => null, 'limit_response_size' => null);
// Get full args
$args = $this->build_args($args, $defaults);
// Get url info
$infoURL = @parse_url($url);
// Check valid url
if (empty($url) or empty($infoURL['scheme'])) {
$this->set_error(1);
return false;
}
// Set SSL
$args['ssl'] = $infoURL['scheme'] == 'https' or $infoURL['scheme'] == 'ssl';
/**
* Block url
* By basic version, all url will be enabled and no blocking by check function
*/
//if( $this->is_blocking( $url ) )
//{
// $this->set_error(2);
// return false;
//}
// Determine if this request is to OUR install of NukeViet
$homeURL = parse_url($this->site_config['my_domain']);
$args['local'] = $homeURL['host'] == $infoURL['host'] || 'localhost' == $infoURL['host'];
unset($homeURL);
// If Stream but no file, default is a file in temp dir with base $url name
if ($args['stream'] and empty($args['filename'])) {
$args['filename'] = $this->tmp_dir . '/' . basename($url);
}
// Check if streaming a file
if ($args['stream']) {
$args['blocking'] = true;
if (!@is_writable(dirname($args['filename']))) {
$this->set_error(3);
return false;
}
}
// Default header is an empty array
if (is_null($args['headers'])) {
$args['headers'] = array();
}
if (!is_array($args['headers'])) {
$processedHeaders = Http::processHeaders($args['headers'], $url);
$args['headers'] = $processedHeaders['headers'];
}
// Get User Agent
if (isset($args['headers']['User-Agent'])) {
$args['user-agent'] = $args['headers']['User-Agent'];
unset($args['headers']['User-Agent']);
}
if (isset($args['headers']['user-agent'])) {
$args['user-agent'] = $args['headers']['user-agent'];
unset($args['headers']['user-agent']);
}
// Get Referer
if (isset($args['headers']['Referer'])) {
$args['referer'] = $args['headers']['Referer'];
unset($args['headers']['Referer']);
} elseif (isset($args['headers']['referer'])) {
$args['referer'] = $args['headers']['referer'];
unset($args['headers']['referer']);
}
if ($args['httpversion'] == '1.1' and !isset($args['headers']['connection'])) {
$args['headers']['connection'] = 'close';
}
Http::buildCookieHeader($args);
Http::mbstring_binary_safe_encoding();
if (!isset($args['headers']['Accept-Encoding'])) {
if ($encoding = Encoding::accept_encoding($url, $args)) {
$args['headers']['Accept-Encoding'] = $encoding;
}
}
if (!is_null($args['body']) and '' != $args['body'] or $args['method'] == 'POST' or $args['method'] == 'PUT') {
if (is_array($args['body']) or is_object($args['body'])) {
$args['body'] = http_build_query($args['body'], null, '&');
if (!isset($args['headers']['Content-Type'])) {
$args['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . $this->site_config['site_charset'];
}
}
if ($args['body'] === '') {
$args['body'] = null;
}
if (!isset($args['headers']['Content-Length']) and !isset($args['headers']['content-length'])) {
$args['headers']['Content-Length'] = strlen($args['body']);
}
}
$response = $this->_dispatch_request($url, $args);
Http::reset_mbstring_encoding();
if ($this->is_error($response)) {
return $response;
}
// Append cookies that were used in this request to the response
//.........这里部分代码省略.........
示例3: request
/**
*
* @param mixed $url
* @param mixed $args
* @return
*/
public function request($url, $args = array())
{
$defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array());
$args = Http::build_args($args, $defaults);
// Get user agent
if (isset($args['headers']['User-Agent'])) {
$args['user-agent'] = $args['headers']['User-Agent'];
unset($args['headers']['User-Agent']);
} elseif (isset($args['headers']['user-agent'])) {
$args['user-agent'] = $args['headers']['user-agent'];
unset($args['headers']['user-agent']);
}
// Get Referer
if (isset($args['headers']['Referer'])) {
$args['referer'] = $args['headers']['Referer'];
unset($args['headers']['Referer']);
} elseif (isset($args['headers']['referer'])) {
$args['referer'] = $args['headers']['referer'];
unset($args['headers']['referer']);
}
// Construct Cookie: header if any cookies are set
Http::buildCookieHeader($args);
$arrURL = parse_url($url);
$connect_host = $arrURL['host'];
$secure_transport = ($arrURL['scheme'] == 'ssl' or $arrURL['scheme'] == 'https');
if (!isset($arrURL['port'])) {
if ($arrURL['scheme'] == 'ssl' or $arrURL['scheme'] == 'https') {
$arrURL['port'] = 443;
$secure_transport = true;
} else {
$arrURL['port'] = 80;
}
}
if (isset($args['headers']['Host']) or isset($args['headers']['host'])) {
if (isset($args['headers']['Host'])) {
$arrURL['host'] = $args['headers']['Host'];
} else {
$arrURL['host'] = $args['headers']['host'];
}
unset($args['headers']['Host'], $args['headers']['host']);
}
// Certain versions of PHP have issues with 'localhost' and IPv6, It attempts to connect to ::1,
// which fails when the server is not set up for it. For compatibility, always connect to the IPv4 address.
if (strtolower($connect_host) == 'localhost') {
$connect_host = '127.0.0.1';
}
$connect_host = $secure_transport ? 'ssl://' . $connect_host : 'tcp://' . $connect_host;
$is_local = isset($args['local']) and $args['local'];
$ssl_verify = isset($args['sslverify']) and $args['sslverify'];
// NukeViet has no proxy setup
$context = stream_context_create(array('ssl' => array('verify_peer' => $ssl_verify, 'capture_peer_cert' => $ssl_verify, 'SNI_enabled' => true, 'cafile' => $args['sslcertificates'], 'allow_self_signed' => !$ssl_verify)));
$timeout = (int) floor($args['timeout']);
$utimeout = $timeout == $args['timeout'] ? 0 : 1000000 * $args['timeout'] % 1000000;
$connect_timeout = max($timeout, 1);
$connection_error = null;
// Store error number
$connection_error_str = null;
// Store error string
// In the event that the SSL connection fails, silence the many PHP Warnings
if ($secure_transport) {
$error_reporting = error_reporting(0);
}
// No proxy option on NukeViet, maybe in future!!!!
//if( $proxy->is_enabled() and $proxy->send_through_proxy( $url ) )
//{
// $handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
//}
//else
//{
$handle = @stream_socket_client($connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context);
//}
if ($secure_transport) {
error_reporting($error_reporting);
}
if ($handle === false) {
// SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken
if ($secure_transport and $connection_error === 0 and $connection_error_str === '') {
Http::set_error(6);
return false;
}
Http::set_error(7);
return false;
}
// Verify that the SSL certificate is valid for this request
if ($secure_transport and $ssl_verify) {
if (!self::verify_ssl_certificate($handle, $arrURL['host'])) {
Http::set_error(6);
return false;
}
}
stream_set_timeout($handle, $timeout, $utimeout);
//if( $proxy->is_enabled() and $proxy->send_through_proxy( $url ) )
//{
// //Some proxies require full URL in this field.
//.........这里部分代码省略.........