本文整理汇总了PHP中curl::setopt方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::setopt方法的具体用法?PHP curl::setopt怎么用?PHP curl::setopt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curl
的用法示例。
在下文中一共展示了curl::setopt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrl
function getUrl($url, $requestType = 'GET', $timeout = 30)
{
$curl = new curl();
$curl->curl($url);
if ($requestType == "POST") {
$postString = "";
foreach ($postArray as $postField => $postValue) {
$postString .= "{$postField}=" . $postValue . "&";
}
$postString .= "Enter=";
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_POSTFIELDS, $postString);
}
$curl->setopt(CURLOPT_FRESH_CONNECT, TRUE);
$curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setopt(CURLOPT_USERAGENT, MAGPIE_USER_AGENT);
$curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
// allow redirects
$curl->setopt(CURLOPT_RETURNTRANSFER, 1);
// return into a variable
$curl->setopt(CURLOPT_FORBID_REUSE, 1);
$curl->setopt(CURLOPT_TIMEOUT, $timeout);
// times out after x seconds
$result = $curl->exec();
// run the whole process
$curl->close();
return $result;
}
示例2: curl
/**
* The contructor is a copy of the stock simplepie File class which has
* been modifed to add in use the Moodle curl class rather than php curl
* functions.
*/
function moodle_simplepie_file($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
{
$this->url = $url;
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
$curl = new curl();
$curl->setopt(array('CURLOPT_HEADER' => true));
try {
$this->headers = $curl->get($url);
} catch (moodle_exception $e) {
$this->error = 'cURL Error: ' . $curl->error;
$this->success = false;
return false;
}
$parser =& new SimplePie_HTTP_Parser($this->headers);
if ($parser->parse()) {
$this->headers = $parser->headers;
$this->body = $parser->body;
$this->status_code = $parser->status_code;
if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) {
$this->redirects++;
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
return $this->SimplePie_File($location, $timeout, $redirects, $headers);
}
}
}
示例3: readFeed
function readFeed($url, $type = '')
{
$this->url = $url;
$this->type = $type;
$urltocapture = new curl($this->url);
$urltocapture->setopt(CURLOPT_HTTPGET, true);
$this->fileRead = $urltocapture->exec();
if (empty($this->fileRead) or !$this->fileRead) {
return 101;
}
$ext = new btext();
$this->feedArray = $ext->xml2array($this->fileRead);
switch ($this->type) {
case 'youtube':
return $this->youtube();
break;
case 'vimeo':
return $this->vimeo();
break;
case 'dailymotion':
return $this->dailymotion();
break;
default:
return false;
break;
}
}
示例4: is_remote_site_valid
/**
* Check if the remote site is valid (not localhost and available by the hub)
* Note: it doesn't matter if the site returns a 404 error.
* The point here is to check if the site exists. It does not matter if the hub can not call the site,
* as by security design, a hub should never call a site.
* However an admin user registering his site should be able to access the site,
* as people searching on the hub.
* So we want:
* a) to check that the url is not a local address
* b) to check that the site return some not empty headers
* (it exists, at least the domain name is registered)
* @param string $url the site url
* @return boolean true if the site is valid
*/
public function is_remote_site_valid($url)
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
//Check if site is valid
if (strpos($url, 'http://localhost') !== false or strpos($url, 'http://127.0.0.1') !== false) {
return false;
}
$curl = new curl();
$curl->setopt(array('CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_MAXREDIRS' => 3));
$curl->head($url);
$info = $curl->get_info();
// Return true if return code is OK (200) or redirection (302).
// Redirection occurs for many reasons including redirection to another site that handles single sign-on.
if ($info['http_code'] === 200 || $info['http_code'] === 302) {
return true;
}
// Some sites respond to head() with a 503.
// As a fallback try get().
// We don't just always do get() as it is much slower than head().
$curl->get($url);
$info = $curl->get_info();
if ($info['http_code'] === 200 || $info['http_code'] === 302) {
return true;
}
return false;
}
示例5: parse_file
/**
* Parses one file (either html or css)
*
* @param string $baseurl (optional) URL of the file where link to this file was found
* @param string $relativeurl relative or absolute link to the file
* @param array $list
* @param bool $mainfile true only for main HTML false and false for all embedded/linked files
*/
protected function parse_file($baseurl, $relativeurl, &$list, $mainfile = false)
{
if (preg_match('/([\'"])(.*)\\1/', $relativeurl, $matches)) {
$relativeurl = $matches[2];
}
if (empty($baseurl)) {
$url = $relativeurl;
} else {
$url = htmlspecialchars_decode(url_to_absolute($baseurl, $relativeurl));
}
if (in_array($url, $this->processedfiles)) {
// avoid endless recursion
return;
}
$this->processedfiles[] = $url;
$curl = new curl();
$curl->setopt(array('CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_MAXREDIRS' => 3));
$msg = $curl->head($url);
$info = $curl->get_info();
if ($info['http_code'] != 200) {
if ($mainfile) {
$list['error'] = $msg;
}
} else {
$csstoanalyze = '';
if ($mainfile && (strstr($info['content_type'], 'text/html') || empty($info['content_type']))) {
// parse as html
$htmlcontent = $curl->get($info['url']);
$ddoc = new DOMDocument();
@$ddoc->loadHTML($htmlcontent);
// extract <img>
$tags = $ddoc->getElementsByTagName('img');
foreach ($tags as $tag) {
$url = $tag->getAttribute('src');
$this->add_image_to_list($info['url'], $url, $list);
}
// analyse embedded css (<style>)
$tags = $ddoc->getElementsByTagName('style');
foreach ($tags as $tag) {
if ($tag->getAttribute('type') == 'text/css') {
$csstoanalyze .= $tag->textContent . "\n";
}
}
// analyse links to css (<link type='text/css' href='...'>)
$tags = $ddoc->getElementsByTagName('link');
foreach ($tags as $tag) {
if ($tag->getAttribute('type') == 'text/css' && strlen($tag->getAttribute('href'))) {
$this->parse_file($info['url'], $tag->getAttribute('href'), $list);
}
}
} else {
if (strstr($info['content_type'], 'css')) {
// parse as css
$csscontent = $curl->get($info['url']);
$csstoanalyze .= $csscontent . "\n";
} else {
if (strstr($info['content_type'], 'image/')) {
// download this file
$this->add_image_to_list($info['url'], $info['url'], $list);
} else {
$list['error'] = get_string('validfiletype', 'repository_url');
}
}
}
// parse all found css styles
if (strlen($csstoanalyze)) {
$urls = extract_css_urls($csstoanalyze);
if (!empty($urls['property'])) {
foreach ($urls['property'] as $url) {
$this->add_image_to_list($info['url'], $url, $list);
}
}
if (!empty($urls['import'])) {
foreach ($urls['import'] as $cssurl) {
$this->parse_file($info['url'], $cssurl, $list);
}
}
}
}
}
示例6: curl
/**
* The contructor is a copy of the stock simplepie File class which has
* been modifed to add in use the Moodle curl class rather than php curl
* functions.
*/
function moodle_simplepie_file($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
{
$this->url = $url;
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
$curl = new curl();
$curl->setopt(array('CURLOPT_HEADER' => true, 'CURLOPT_TIMEOUT' => $timeout, 'CURLOPT_CONNECTTIMEOUT' => $timeout));
if ($headers !== null) {
// translate simplepie headers to those class curl expects
foreach ($headers as $headername => $headervalue) {
$headerstr = "{$headername}: {$headervalue}";
$curl->setHeader($headerstr);
}
}
$this->headers = $curl->get($url);
if ($curl->error) {
$this->error = 'cURL Error: ' . $curl->error;
$this->success = false;
return false;
}
$parser = new SimplePie_HTTP_Parser($this->headers);
if ($parser->parse()) {
$this->headers = $parser->headers;
$this->body = $parser->body;
$this->status_code = $parser->status_code;
if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) {
$this->redirects++;
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
return $this->moodle_simplepie_file($location, $timeout, $redirects, $headers);
}
}
}
示例7: calendar_get_icalendar
/**
* From a URL, fetch the calendar and return an iCalendar object.
*
* @param string $url The iCalendar URL
* @return stdClass The iCalendar object
*/
function calendar_get_icalendar($url)
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$curl = new curl();
$curl->setopt(array('CURLOPT_FOLLOWLOCATION' => 1, 'CURLOPT_MAXREDIRS' => 5));
$calendar = $curl->get($url);
// Http code validation should actually be the job of curl class.
if (!$calendar || $curl->info['http_code'] != 200 || !empty($curl->errorno)) {
throw new moodle_exception('errorinvalidicalurl', 'calendar');
}
$ical = new iCalendar();
$ical->unserialize($calendar);
return $ical;
}
示例8: makeRequest
/**
* internal function that I use to make all the requests to flickr
*
* @param string $method The Flickr Method that is being requested
* @param array $params An array of the various required and optional fields needed to make the mthod request
*
* @return array The xml turned into an array
* @access public
*/
function makeRequest($method, $params)
{
$this->_clearErrors();
$useCURL = in_array('curl', get_loaded_extensions());
$params['method'] = $method;
$params['api_key'] = $this->_api_key;
$args = array();
foreach ($params as $k => $v) {
array_push($args, urlencode($k) . '=' . urlencode($v));
}
$query_str = implode('&', $args);
$request = $this->_flickr_api_url . '?' . $query_str;
// full url to request
$hit_flickr = true;
// whether or not to make a request to flickr
$request_hash = md5($request);
if ($this->_cache_enabled) {
if ($this->_cache_type == 'db') {
$now = time();
$rows = $this->_cache->findMany("WHERE request = '" . $request_hash . "' AND date_expire > {$now}");
// if any rows found, then use cached response
if (count($rows) > 0) {
$xml = $rows[0]->response;
$hit_flickr = $xml == '' ? true : false;
}
} else {
$now = time();
$file = $this->_cache_dir . md5($request) . '.cache';
if (file_exists($file)) {
$xml = file_get_contents($file);
$hit_flickr = $xml == '' ? true : false;
}
}
}
// only hit flickr if cached request not found above
if ($hit_flickr) {
// whether or not to use curl for request
if ($useCURL) {
$c = new curl($request);
$c->setopt(CURLOPT_FOLLOWLOCATION, true);
$xml = $c->exec();
$error = $c->hasError();
if ($error) {
$this->_error_msg = $error;
return false;
}
$c->close();
} else {
// curl not available so use fsockopen
$url_parsed = parse_url($request);
$host = $url_parsed["host"];
$port = $url_parsed['port'] == 0 ? 80 : $url_parsed['port'];
$path = $url_parsed["path"] . ($url_parsed['query'] != '' ? $path .= "?{$url_parsed[query]}" : '');
$headers = "GET {$path} HTTP/1.0\r\n";
$headers .= "Host: {$host}\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
$this->_error_msg = $errstr;
$this->_error_code = $errno;
return false;
} else {
fwrite($fp, $headers);
while (!feof($fp)) {
$xml .= fgets($fp, 1024);
}
fclose($fp);
/*
this seems stupid, but it removes the
headers from the response; if you know
a better way let me know
*/
$xml_start = strpos($xml, '<?xml');
$xml = substr($xml, $xml_start, strlen($xml));
}
}
if ($this->_cache_enabled) {
// store the cached request
if ($this->_cache_type == 'db') {
$this->_cache->request = $request_hash;
$this->_cache->response = $xml;
$this->_cache->date_expire = strtotime("+ {$this->_cache_expire} seconds", time());
$this->_cache->save();
} else {
$file = $this->_cache_dir . $request_hash . '.cache';
$fp = fopen($file, "w");
$result = fwrite($fp, $xml);
fclose($fp);
}
}
}
if ($this->_debug) {
//.........这里部分代码省略.........
示例9: curl
function fetch_request($request)
{
$c = new curl(array('cache' => true, 'module_cache' => 'tag_youtube'));
$c->setopt(array('CURLOPT_TIMEOUT' => 3, 'CURLOPT_CONNECTTIMEOUT' => 3));
$response = $c->get($request);
$xml = new SimpleXMLElement($response);
return $this->render_video_list($xml);
}
示例10: strtolower
$array['error'] = "Please enter file url";
echo json_encode($array);
exit;
}
//Checkinf if extension is wrong
$types = strtolower($Cbucket->configs['allowed_types']);
$types_array = preg_replace('/,/', ' ', $types);
$types_array = explode(' ', $types_array);
$extension_whitelist = $types_array;
if (!in_array($ext, $extension_whitelist)) {
$array['error'] = "This file type is not allowed";
echo json_encode($array);
exit;
}
$curl = new curl($file);
$curl->setopt(CURLOPT_FOLLOWLOCATION, true);
//Checking if file size is not that goood
if (!is_numeric($curl->file_size) || $curl->file_size == '') {
$array['error'] = "Unknown file size";
echo json_encode($array);
exit;
}
if (phpversion() < '5.3.0') {
//Here we will get file size and write it in a file
//called dummy_log
$darray = array('file_size' => $curl->file_size, 'file_name' => $file_name . '.' . $ext, 'time_started' => time(), 'byte_size' => 0);
$do = fopen($dummy_file, 'w+');
fwrite($do, json_encode($darray));
fclose($do);
}
//Opening video file
示例11: capture
function capture()
{
$obj = new stdClass();
$arry = $this->readFeed($this->feed['url'], $this->feed['type']);
$obj->title = $arry['title'];
$obj->description = $arry['description'];
$obj->videoThumbnail = $arry['videoThumbnail'];
$obj->videoTags = $arry['videoTags'];
$obj->videoSrc = $arry['videoSrc'];
if (empty($obj->title) or empty($obj->videoSrc) or empty($obj->videoThumbnail)) {
if (!empty($arry['error'])) {
return $arry['error'];
} else {
return $arry;
}
}
$obj->fileName = time() . $this->video_id . ".jpg";
$urltocapture = new curl($obj->videoThumbnail);
$urltocapture->setopt(CURLOPT_HTTPGET, true);
$obj->fileContent = $urltocapture->exec();
$obj->type = $this->feed['type'];
return $obj;
}
示例12: validate_receiver
public function validate_receiver($receiver)
{
$plagiarismsettings = $this->get_settings();
$url = URKUND_INTEGRATION_SERVICE . '/receivers' . '/' . trim($receiver);
$headers = array('Accept-Language: ' . $plagiarismsettings['urkund_lang']);
$allowedstatus = array(URKUND_STATUSCODE_PROCESSED, URKUND_STATUSCODE_NOT_FOUND, URKUND_STATUSCODE_BAD_REQUEST, URKUND_STATUSCODE_GONE);
// Use Moodle curl wrapper.
$c = new curl(array('proxy' => true));
$c->setopt(array());
$c->setopt(array('CURLOPT_RETURNTRANSFER' => 1, 'CURLOPT_HTTPAUTH' => CURLAUTH_BASIC, 'CURLOPT_USERPWD' => $plagiarismsettings['urkund_username'] . ":" . $plagiarismsettings['urkund_password']));
$c->setHeader($headers);
$response = $c->get($url);
$httpstatus = $c->info['http_code'];
if (!empty($httpstatus)) {
if (in_array($httpstatus, $allowedstatus)) {
if ($httpstatus == URKUND_STATUSCODE_PROCESSED) {
// Valid address found, return true.
return true;
} else {
return $httpstatus;
}
}
}
return false;
}
示例13: fetch_request
/**
* Sends a request to fetch data.
*
* @see block_tag_youtube::service
* @deprecated since Moodle 2.8.8, 2.9.2 and 3.0 MDL-49085 - please do not use this function any more.
* @param string $request
* @throws coding_exception
*/
public function fetch_request($request)
{
throw new coding_exception('Sorry, this function has been deprecated in Moodle 2.8.8, 2.9.2 and 3.0. Use block_tag_youtube::get_service instead.');
$c = new curl(array('cache' => true, 'module_cache' => 'tag_youtube'));
$c->setopt(array('CURLOPT_TIMEOUT' => 3, 'CURLOPT_CONNECTTIMEOUT' => 3));
$response = $c->get($request);
$xml = new SimpleXMLElement($response);
return $this->render_video_list($xml);
}
示例14: curl
<?php
include_once "class.curl.php";
//
// Create a new instance of the curl class and point it
// at the page to be fetched.
//
$c = new curl("http://www.csworks.com/resume/cv.shtml");
//
// By default, curl doesn't follow redirections and this
// page may or may not be available via redirection.
//
$c->setopt(CURLOPT_FOLLOWLOCATION, true);
//
// By default, the curl class expects to return data to
// the caller.
//
echo $c->exec();
//
// Check to see if there was an error and, if so, print
// the associated error message.
//
if ($theError = $c->hasError()) {
echo $theError;
}
//
// Done with the cURL, so get rid of the cURL related resources.
//
$c->close();
示例15: curl_post
private function curl_post($URL = NULL, $POST_DATA = NULL)
{
if ($URL == NULL || $POST_DATA == NULL) {
trigger_error("curl_post() ERROR: URL or POST_DATA has not been setted.", E_USER_ERROR);
}
$URL = new curl($URL);
$URL->setopt(CURLOPT_FOLLOWLOCATION, TRUE);
$URL->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$URL->setopt(CURLOPT_SSL_VERIFYHOST, FALSE);
$URL->setopt(CURLOPT_POST, TRUE);
$URL->setopt(CURLOPT_POSTFIELDS, $POST_DATA);
$URL->setopt(CURLOPT_USERAGENT, "User-Agent: IIC2.0/PC 2.3.0230");
$curl_result = $URL->exec();
if ($theError = $URL->hasError()) {
echo $theError;
}
$URL->close();
return $curl_result;
}