本文整理汇总了PHP中http_parse_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP http_parse_headers函数的具体用法?PHP http_parse_headers怎么用?PHP http_parse_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了http_parse_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
function initialize()
{
if (!$this->fetched) {
$config =& get_config();
$assetUrl = $config['asset_service'] . $this->node['AssetID'];
$curl = new Curl();
$curl->create($assetUrl);
$curl->option(CURLOPT_HEADER, true);
$curl->option(CURLOPT_NOBODY, true);
$response = $curl->execute();
if ($response) {
$headers = http_parse_headers($response);
$this->size = $headers['Content-Length'];
$this->contentType = $headers['Content-Type'];
if (isset($headers['ETag'])) {
$this->etag = $headers['ETag'];
} else {
if (isset($headers['Etag'])) {
$this->etag = $headers['Etag'];
} else {
$this->etag = '';
}
}
} else {
log_message('error', "InventoryFile: Failed to fetch headers from {$assetUrl}");
}
$this->fetched = true;
}
}
示例2: parseHeaders
/**
* if PECL_HTTP is not available use a fall back function
*
* thanks to ricardovermeltfoort@gmail.com
* http://php.net/manual/en/function.http-parse-headers.php#112986
* @param string $raw_headers raw headers
* @return array
*/
private function parseHeaders($raw_headers)
{
if (function_exists('http_parse_headers')) {
return http_parse_headers($raw_headers);
} else {
$key = '';
$headers = array();
foreach (explode("\n", $raw_headers) as $i => $h) {
$h = explode(':', $h, 2);
if (isset($h[1])) {
if (!isset($headers[$h[0]])) {
$headers[$h[0]] = trim($h[1]);
} elseif (is_array($headers[$h[0]])) {
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
} else {
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
}
$key = $h[0];
} else {
if (substr($h[0], 0, 1) == "\t") {
$headers[$key] .= "\r\n\t" . trim($h[0]);
} elseif (!$key) {
$headers[0] = trim($h[0]);
}
}
}
return $headers;
}
}
示例3: parse_header_string
/**
* Parses a HTTP header string into an associative array
*
* @param string $header_string Header string to parse
* @return HTTP_Header
*/
public static function parse_header_string($header_string)
{
// If the PECL HTTP extension is loaded
if (extension_loaded('http')) {
// Use the fast method to parse header string
return new HTTP_Header(http_parse_headers($header_string));
}
// Otherwise we use the slower PHP parsing
$headers = array();
// Match all HTTP headers
if (preg_match_all('/(\\w[^\\s:]*):[ ]*([^\\r\\n]*(?:\\r\\n[ \\t][^\\r\\n]*)*)/', $header_string, $matches)) {
// Parse each matched header
foreach ($matches[0] as $key => $value) {
// If the header has not already been set
if (!isset($headers[$matches[1][$key]])) {
// Apply the header directly
$headers[$matches[1][$key]] = $matches[2][$key];
} else {
// If the entry is an array
if (is_array($headers[$matches[1][$key]])) {
// Apply the new entry to the array
$headers[$matches[1][$key]][] = $matches[2][$key];
} else {
$headers[$matches[1][$key]] = array($headers[$matches[1][$key]], $matches[2][$key]);
}
}
}
}
// Return the headers
return new HTTP_Header($headers);
}
示例4: executeMultiRequest
/**
* Executes a curl request.
*
* @param resource $request
* @return \Frlnc\Slack\Contracts\Http\Response
*/
public function executeMultiRequest($multiRequest, $singleRequests)
{
$responses = [];
$infos = [];
$active = null;
do {
$status = curl_multi_exec($multiRequest, $active);
$infos[] = curl_multi_info_read($multiRequest);
} while ($status === CURLM_CALL_MULTI_PERFORM || $active);
foreach ($singleRequests as $index => $singleRequest) {
$body = curl_multi_getcontent($singleRequest);
curl_multi_remove_handle($multiRequest, $singleRequest);
curl_close($singleRequest);
$info = $infos[$index];
$statusCode = $info['http_code'];
$headers = $info['request_header'];
if (function_exists('http_parse_headers')) {
$headers = http_parse_headers($headers);
} else {
$header_text = substr($headers, 0, strpos($headers, "\r\n\r\n"));
$headers = [];
foreach (explode("\r\n", $header_text) as $i => $line) {
if ($i !== 0) {
list($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
}
}
$responses[] = $this->factory->build($body, $headers, $statusCode);
}
curl_multi_close($multiRequest);
return $responses;
}
示例5: parseHeaders
/**
* @param $raw
* @return array
*/
public static function parseHeaders($raw)
{
if (!$raw) {
return [];
}
if (function_exists('http_parse_headers')) {
return http_parse_headers($raw);
}
$headers = [];
$key = '';
foreach (explode("\n", $raw) as $h) {
$h = explode(':', $h, 2);
if (isset($h[1])) {
if (!isset($headers[$h[0]])) {
$headers[$h[0]] = trim($h[1]);
} elseif (is_array($headers[$h[0]])) {
$headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]);
} else {
$headers[$h[0]] = array_merge(array($headers[$h[0]]), [trim($h[1])]);
}
$key = $h[0];
} else {
if (substr($h[0], 0, 1) == "\t") {
$headers[$key] .= "\r\n\t" . trim($h[0]);
} elseif (!$key) {
$headers[0] = trim($h[0]);
}
}
}
return $headers;
}
示例6: message
function message($cookie, $id, $subject = 'None', $body = 'None', $save = '../Private/mxcsrf.txt')
{
$xcsrf = file_exists($save) ? file_get_contents($save) : '';
$curl = curl_init('http://www.roblox.com/messages/send');
$send = array('subject' => $subject, 'body' => $body, 'recipientid' => $id, 'cacheBuster' => time());
curl_setopt_array($curl, array(CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array("X-CSRF-TOKEN: {$xcsrf}"), CURLOPT_POST => true, CURLOPT_POSTFIELDS => $send, CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie, CURLOPT_RETURNTRANSFER => true));
$response = curl_exec($curl);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($responseCode != 200) {
if ($responseCode == 403) {
// 403 XCSRF Token Validation Failed
$header = http_parse_headers(substr($response, 0, $headerSize));
$xcsrf = $header['X-CSRF-TOKEN'];
file_put_contents($save, $xcsrf);
return message($cookie, $id, $subject, $body, $save);
}
}
$json = json_decode(substr($response, $headerSize), true);
if ($json['success']) {
return "Sent message {$subject} to {$id}.";
} else {
$error = $json['shortMessage'];
return "Error sending message {$subject} to {$id}: {$error}";
}
}
示例7: loadFromURL
protected function loadFromURL($url)
{
$image = file_get_contents($url);
$headers = http_parse_headers(implode("\r\n", $http_response_header));
$ext = array_search($headers['Content-Type'], $mimeExtensions);
return array($image, $ext);
}
示例8: execute
protected function execute($arguments = array(), $options = array())
{
// initialize the database connection
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
// add your code here
$blogs = Doctrine::getTable('Blog');
$blogs_to_process = $blogs->findByIsThumbnail(0);
foreach ($blogs_to_process as $blog) {
$thumbalizr_url = 'http://api.thumbalizr.com?';
$params = array('url' => $blog->url, 'width' => 300);
$api_url = $thumbalizr_url . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
$res_tab = http_parse_headers($res);
if (!empty($res_tab['X-Thumbalizr-Status']) && $res_tab['X-Thumbalizr-Status'] == 'OK') {
// Image is ready let's store the URL!
$image_data = file_get_contents($api_url);
$path = sfConfig::get('app_image_path');
$url = sfConfig::get('app_image_url');
$image_name = md5($blog->url);
echo $path . $image_name . "\n";
file_put_contents($path . $image_name . '.jpg', $image_data);
$blog->thumbnail_url = $image_name . '.jpg';
$blog->is_thumbnail = 1;
$blog->save();
// Send mail to notify the blo will get into the game!
try {
// Create the mailer and message objects
//$mailer = new Swift(new Swift_Connection_NativeMail());
//$connection = new Swift_Connection_SMTP('smtp.free.fr');
$connection = new Swift_Connection_NativeMail();
$mailer = new Swift($connection);
$message = new Swift_Message('Welcome!');
// Render message parts
$mailContext = array('admin_hash' => $blog->getAdmin_hash(), 'blog_url' => $blog->getUrl());
$v = $this->getPartial('newBlogMailHtmlBody', $mailContext);
$htmlPart = new Swift_Message_Part($v, 'text/html');
$message->attach($htmlPart);
$message->attach(new Swift_Message_Part($this->getPartial('newBlogMailTextBody', $mailContext), 'text/plain'));
$mailTo = $blog->getEmail();
$mailFrom = sfConfig::get('app_mail_webmaster');
$mailer->send($message, $mailTo, $mailFrom);
$mailer->disconnect();
} catch (Exception $e) {
$this->logMessage($e);
}
} else {
//print_r($res_tab);
}
}
}
示例9: header_fetch
function header_fetch($url, $check_against)
{
$data = get_url($url, true);
$headers = http_parse_headers($data);
foreach ($headers as $key => $value) {
if ($key == $check_against->header_option) {
echo $key . ': ' . $value;
}
}
}
示例10: getPingbackServerURL
public static function getPingbackServerURL($url)
{
(new Chainable(new cURL($url)))->setopt(CURLOPT_HEADER, true)->setopt(CURLOPT_NOBODY, true)->setopt(CURLOPT_RETURNTRANSFER, true)->exec()->_get_return($curldata)->close();
$headers = http_parse_headers($curldata);
if (isset($headers['X-Pingback']) && !empty($headers['X-Pingback'])) {
return $headers['X-Pingback'];
}
$response = file_get_contents($url);
return preg_match(self::REGEXP_PINGBACK_LINK, $response, $match) ? $match[1] : false;
}
示例11: parseHeader
function parseHeader($header)
{
$head = http_parse_headers($header);
if ($head === false) {
return false;
} else {
$head[0]['protocol'] = "HTTP/1.1";
$head[0]['uri'] = $head["Request Url"];
$head[0]['method'] = $head["Request Method"];
}
return $head;
}
示例12: getHeaders
/**
* Return the headers as associative array or return the given header.
* @param string $key
* @return string|string[]
*/
public function getHeaders($key = null)
{
if (!$this->headers) {
$this->headers = http_parse_headers($this->rawHeaders);
}
if ($key) {
if (isset($this->headers[$key])) {
return $this->headers[$key];
}
}
return $this->headers;
}
示例13: updateRank
function updateRank($group, $userId, $rank, $cookie, $ranks, $roles, $rankLimit = 255, $save = '../Private/gxcsrf.txt')
{
// OH MY GOD SO MANY ARGUMENTS!
$xcsrf = file_exists($save) ? file_get_contents($save) : '';
/*
If you want to increase performance do this:
Move the following line (currentRank) into the rankLimit if statement.
Change the success return to something simpler (does not return user's previous rank)
This doesn't actually slow it down that much at all, but when changing ranks **IN BULK** you will be making a lot of requests.
*/
$currentRank = getRankInGroup($userId, $group);
if ($rankLimit && $rankLimit < 255) {
if ($rank > $rankLimit || $currentRank > $rankLimit) {
// Check if the rank you are trying to change them to and their rank abide to the rank limit
return "Settings restrict the system from changing any rank over {$rankLimit}.";
}
}
$url = "http://www.roblox.com/groups/api/change-member-rank?groupId={$group}&newRoleSetId=" . getRoleSet($ranks, $rank) . "&targetUserId={$userId}";
// Get rank URL
$curl = curl_init($url);
curl_setopt_array($curl, array(CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array("X-CSRF-TOKEN: {$xcsrf}", 'Content-Length: 0'), CURLOPT_POST => true, CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie, CURLOPT_RETURNTRANSFER => true));
$response = curl_exec($curl);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($responseCode != 200) {
// BELOW 302 DOES NOT WORK AND IS DEPRACATED FOR NOW
/*if ($responseCode == 302) { // 302 Moved temporarily - User is not logged in: Redirect to error page
login($cookie,$username,$password);
return updateRank($username,$password,$group,$userId,$rank,$cookie,$ranks,$roles,$rankLimit,$save); // Would appreciate if someone showed me a better way to do this (not repassing every argument manually).
} else */
if ($responseCode == 403) {
// 403 XCSRF Token Validation Failed - CONVENIENCE!
$header = http_parse_headers(substr($response, 0, $headerSize));
$xcsrf = $header['X-CSRF-TOKEN'];
file_put_contents($save, $xcsrf);
return updateRank($group, $userId, $rank, $cookie, $ranks, $roles, $rankLimit, $save);
}
}
$response = substr($response, $headerSize);
curl_close($curl);
if (json_decode($response, true)['success'] == false) {
return 'Invalid promoting permissions.';
} else {
$current = getRoleSet($ranks, $currentRank);
$new = getRoleSet($ranks, $rank);
return "Successfully changed rank of user {$userId} from " . $roles[$current] . ' to ' . $roles[$new] . '.';
// Details!
}
}
示例14: getPingbackServerURL
public static function getPingbackServerURL($url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = http_parse_headers(curl_exec($curl));
curl_close($curl);
if (isset($headers['X-Pingback']) && !empty($headers['X-Pingback'])) {
return $headers['X-Pingback'];
}
$response = file_get_contents($url);
return preg_match(self::REGEXP_PINGBACK_LINK, $response, $match) ? $match[1] : false;
}
示例15: handleJoinRequest
function handleJoinRequest($cookie, $group, $username, $choice, $save = 'hxcsrf.txt', $requestId = -1)
{
$xcsrf = file_exists($save) ? file_get_contents($save) : '';
$url = "http://www.roblox.com/My/GroupAdmin.aspx?gid={$group}";
switch ($choice) {
case 'Accept':
$choiceNumber = 1;
break;
case 'Decline':
$choiceNumber = 2;
break;
default:
die('Invalid choice.');
}
if ($requestId === -1) {
// This is so that if the function is being re called with the request ID already received you don't go through the whole process again (because it takes up a lot of time)
$curl = curl_init($url);
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie));
$response = curl_exec($curl);
$nextPost = getPostArray(substr($response, curl_getinfo($curl, CURLINFO_HEADER_SIZE)), array('ctl00$ctl00$cphRoblox$cphMyRobloxContent$JoinRequestsSearchBox' => $username, 'ctl00$ctl00$cphRoblox$cphMyRobloxContent$JoinRequestsSearchButton' => 'Search'));
curl_close($curl);
$curl = curl_init($url);
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $nextPost, CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie));
$response = curl_exec($curl);
$doc = new DOMDocument();
$doc->loadHTML($response);
$find = new DomXPath($doc);
$nodes = $find->query("//span[contains(@class,'btn-control btn-control-medium accept-join-request')][1]");
foreach ($nodes as $node) {
$requestId = $node->getAttribute('data-rbx-join-request');
}
}
$curl = curl_init('http://www.roblox.com/group/handle-join-request');
$post = array('groupJoinRequestId' => $requestId, 'accept' => $choiceNumber == 1 ? true : false);
curl_setopt_array($curl, array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($post), CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array("X-CSRF-TOKEN: {$xcsrf}", 'Content-Length: ' . strlen(json_encode($post)), 'Content-Type: application/json; charset=UTF-8'), CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie, CURLOPT_RETURNTRANSFER => true));
$response = curl_exec($curl);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($responseCode != 200) {
if ($responseCode == 403) {
// 403 XCSRF Token Validation Failed
$header = http_parse_headers(substr($response, 0, $headerSize));
$xcsrf = $header['X-CSRF-TOKEN'];
file_put_contents($save, $xcsrf);
return handleJoinRequest($cookie, $group, $username, $choice, $save, $requestId);
}
}
$text = $choiceNumber == 1 ? 'ed' : 'd';
return "{$choice}{$text} {$username}'s join request.";
}