本文整理汇总了PHP中cURL函数的典型用法代码示例。如果您正苦于以下问题:PHP cURL函数的具体用法?PHP cURL怎么用?PHP cURL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetPage
public function GetPage($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $XMLRequest = 0)
{
if (!$referer && !empty($GLOBALS['Referer'])) {
$referer = $GLOBALS['Referer'];
}
$cURL = $GLOBALS['options']['use_curl'] && extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_exec') ? true : false;
$Url = parse_url(trim($link));
if (strtolower($Url['scheme']) == 'https') {
$chttps = false;
if ($cURL) {
$cV = curl_version();
if (in_array('https', $cV['protocols'], true)) {
$chttps = true;
}
}
if (!extension_loaded('openssl') && !$chttps) {
html_error('You need to install/enable PHP\'s OpenSSL extension to support HTTPS connections.');
} elseif (!$chttps) {
$cURL = false;
}
}
if ($cURL) {
if ($XMLRequest) {
$referer .= "\r\nX-Requested-With: XMLHttpRequest";
}
$page = cURL($link, $cookie, $post, $referer, $auth);
} else {
global $pauth;
$page = geturl($Url['host'], defport($Url), $Url['path'] . (!empty($Url['query']) ? '?' . $Url['query'] : ''), $referer, $cookie, $post, 0, !empty($_GET['proxy']) ? $_GET['proxy'] : '', $pauth, $auth, $Url['scheme'], 0, $XMLRequest);
is_page($page);
}
return $page;
}
示例2: array_sha
function array_sha($findgit, $all = false, $page = 1, $per_page = 100, $array = array())
{
$url = "https://api.github.com/repos/" . $findgit . "/commits?page=" . $page . "&per_page=" . $per_page;
$json = cURL($url);
if (isset($json['message'])) {
return $json;
}
foreach ($json as $key => $value) {
$file = "";
if (isset($value['sha'])) {
if (!$all) {
$url = "https://api.github.com/repos/" . $findgit . "/commits/" . $value['sha'];
$files = cURL($url);
if (isset($files['files'])) {
foreach ($files['files'] as $val) {
$file .= $val['filename'] . "<br>";
}
}
}
$array[] = array('sha' => $value['sha'], 'name' => $value['commit']['committer']['name'], 'date' => $value['commit']['committer']['date'], 'message' => $value['commit']['message'], 'files' => $file);
}
}
if (++$key == $per_page && $all) {
$array = array_sha($findgit, $all, ++$page, $per_page, $array);
}
return $array;
}
示例3: getChapter
function getChapter($url, $debug)
{
$content = extract_id(cURL($url), "storytext", $debug);
$content = str_replace(array("‘", "’", "“", "”", "–", "—", "…"), array("'", "'", '"', '"', '-', '--', '...'), $content);
$content = str_replace(array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)), array("'", "'", '"', '"', '-', '--', '...'), $content);
return $content;
}
示例4: GetPage
public function GetPage($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $XMLRequest = 0)
{
global $options;
if (!$referer) {
global $Referer;
$referer = $Referer;
}
$cURL = $options['use_curl'] && extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_exec') ? true : false;
$Url = parse_url(trim($link));
if ($Url['scheme'] == 'https') {
$chttps = false;
if ($cURL) {
$cV = curl_version();
if (in_array('https', $cV['protocols'], true)) {
$chttps = true;
}
}
if (!extension_loaded('openssl') && !$chttps) {
html_error('This server doesn\'t support https connections.');
} elseif (!$chttps) {
$cURL = false;
}
}
if ($cURL) {
if ($XMLRequest) {
$referer .= "\r\nX-Requested-With: XMLHttpRequest";
}
$page = cURL($link, $cookie, $post, $referer, $auth);
} else {
global $pauth;
$page = geturl($Url['host'], defport($Url), $Url['path'] . (!empty($Url['query']) ? '?' . $Url['query'] : ''), $referer, $cookie, $post, 0, !empty($_GET['proxy']) ? $_GET['proxy'] : '', $pauth, $auth, $Url['scheme'], 0, $XMLRequest);
is_page($page);
}
return $page;
}
示例5: getHPFanficArchiveInfo
function getHPFanficArchiveInfo($url)
{
$urlParts = parse_url($url);
parse_str($urlParts['query'], $query);
if (isset($query['sid'])) {
$storyId = $query['sid'];
if (is_numeric($storyId)) {
$url = "{$urlParts['scheme']}://{$urlParts['host']}/stories/viewstory.php?sid={$storyId}";
$response = cURL($url);
$html = new HTML5();
$html = $html->loadHTML($response);
$story = new Story();
$story->id = $storyId;
$story->url = $url;
$title = qp($html, '#pagetitle')->find('a[href^="viewstory"]')->first()->text();
if (empty($title)) {
throw new FicSaveException("Could not retrieve title for story at {$url}.");
} else {
$story->title = $title;
}
$author = qp($html, '#pagetitle')->find('a[href^="viewuser"]')->first()->text();
if (empty($author)) {
throw new FicSaveException("Could not retrieve author for story at {$url}.");
} else {
$story->author = $author;
}
$description = qp($html, '#mainpage')->find('.block')->get(1);
if ($description == NULL) {
throw new FicSaveException("Could not retrieve description for story at {$url}.");
} else {
$story->description = stripAttributes(preg_replace('/<a(.*?)>(.*?)<\\/a>/', '\\2', trim(qp($description)->find('.content')->first()->innerHTML())));
}
$chaptersBlock = qp($html, '#mainpage')->find('.block')->get(3);
if ($chaptersBlock == NULL) {
throw new FicSaveException("Could not get number of chapters for story at {$url}.");
} else {
$chapterLinks = qp($chaptersBlock)->find('a[href^="viewstory"]');
$numChapters = $chapterLinks->count();
if ($numChapters > 0) {
$story->chapters = $numChapters;
$story->metadata = array();
foreach ($chapterLinks as $chapterLink) {
$story->metadata[] = $chapterLink->text();
}
} else {
throw new FicSaveException("Could not get number of chapters for story at {$url}.");
}
}
return $story;
} else {
throw new FicSaveException("URL has an invalid story ID: {$storyId}.");
}
} else {
throw new FicSaveException("URL is missing story ID.");
}
}
示例6: getFanfictionNetInfo
function getFanfictionNetInfo($url)
{
$urlParts = parse_url($url);
$pathParts = explode('/', $urlParts['path']);
if (isset($pathParts[2])) {
$storyId = $pathParts[2];
if (is_numeric($storyId)) {
$response = cURL($url);
$html = new HTML5();
$html = $html->loadHTML($response);
$story = new Story();
$story->id = $storyId;
$urlParts = parse_url($url);
$story->url = "{$urlParts['scheme']}://{$urlParts['host']}/s/{$storyId}";
$title = qp($html, '#profile_top')->find('b')->first()->text();
if (empty($title)) {
throw new FicSaveException("Could not retrieve title for story at {$url}.");
} else {
$story->title = $title;
}
$author = qp($html, '#profile_top')->find('a')->first()->text();
if (empty($author)) {
throw new FicSaveException("Could not retrieve author for story at {$url}.");
} else {
$story->author = $author;
}
$description = qp($html, '#profile_top')->find('div')->get(2);
if ($description == NULL) {
throw new FicSaveException("Could not retrieve description for story at {$url}.");
} else {
$story->description = stripAttributes(preg_replace('/<a(.*?)>(.*?)<\\/a>/', '\\2', trim(qp($description)->html() . qp($description)->next()->html())));
}
$numChapters = qp($html, '#chap_select')->find('option')->count() / 2;
// value is always doubled for some reason
$story->chapters = $numChapters == 0 ? 1 : $numChapters;
$coverImageUrl = qp($html, '#profile_top')->find('img')->first()->attr('src');
if ($coverImageUrl != NULL) {
$coverImageUrlParts = parse_url($coverImageUrl);
if (!isset($coverImageUrlParts['scheme']) && substr($coverImageUrl, 0, 2) == '//') {
$coverImageUrl = $urlParts['scheme'] . ":" . $coverImageUrl;
}
$coverImageUrl = str_replace('/75/', '/180/', $coverImageUrl);
$story->coverImageUrl = $coverImageUrl;
}
return $story;
} else {
throw new FicSaveException("URL has an invalid story ID: {$storyId}.");
}
} else {
throw new FicSaveException("URL is missing story ID.");
}
}
示例7: getChapter
function getChapter($url, $debug, $cookies, $uniqid)
{
$dom = new DOMDocument();
$dom->loadHTML(cURL($url, $debug, $cookies, $uniqid));
$xpath = new DOMXPath($dom);
$xpath_content = $xpath->query("//tr[4]/td");
$content = "";
foreach ($xpath_content as $node_content) {
$content = $node_content->ownerDocument->saveHTML($node_content);
}
$content = str_replace(array("‘", "’", "“", "”", "–", "—", "…"), array("'", "'", '"', '"', '-', '--', '...'), $content);
$content = str_replace(array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)), array("'", "'", '"', '"', '-', '--', '...'), $content);
return $content;
}
示例8: getAsianFanficsInfo
function getAsianFanficsInfo($url)
{
$urlParts = parse_url($url);
$pathParts = explode('/', $urlParts['path']);
if (isset($pathParts[3])) {
$storyId = $pathParts[3];
if (is_numeric($storyId)) {
$url = "{$urlParts['scheme']}://{$urlParts['host']}/story/view/{$storyId}";
$response = cURL($url);
$html = new HTML5();
$html = $html->loadHTML($response);
$story = new Story();
$story->id = $storyId;
$story->url = $url;
$title = trim(qp($html, 'h1.title')->first()->text());
if (empty($title)) {
throw new FicSaveException("Could not retrieve title for story at {$url}.");
} else {
$story->title = $title;
}
$author = qp(qp($html, 'span.text--info')->get(0))->next()->text();
if (empty($author)) {
throw new FicSaveException("Could not retrieve author for story at {$url}.");
} else {
$story->author = $author;
}
$description = qp($html, '#bodyText')->find('h2')->first()->next();
if ($description == NULL) {
throw new FicSaveException("Could not retrieve description for story at {$url}.");
} else {
$story->description = stripAttributes(trim($description->innerHTML()));
}
$story->chapters = qp($html, 'select[name="chapterNav"]')->find('option')->count() - 1;
return $story;
} else {
throw new FicSaveException("URL has an invalid story ID: {$storyId}.");
}
} else {
throw new FicSaveException("URL is missing story ID.");
}
}
示例9: getAdultFanfictionOrgInfo
function getAdultFanfictionOrgInfo($url)
{
$urlParts = parse_url($url);
parse_str($urlParts['query'], $query);
if (isset($query['no'])) {
$storyId = $query['no'];
if (is_numeric($storyId)) {
$response = cURL($url);
$html = new HTML5();
$html = $html->loadHTML($response);
$story = new Story();
$story->id = $storyId;
$urlParts = parse_url($url);
$story->url = "{$urlParts['scheme']}://{$urlParts['host']}/story.php?no={$storyId}";
$title = trim(str_replace('Story:', '', qp($html, 'title')->text()));
if (empty($title)) {
throw new FicSaveException("Could not retrieve title for story at {$url}.");
} else {
$story->title = $title;
}
$author = trim(qp(qp($html, 'tr.catdis')->find('td')->get(1))->find('a')->text());
if (empty($author)) {
throw new FicSaveException("Could not retrieve author for story at {$url}.");
} else {
$story->author = $author;
}
$numChapters = qp($html, 'select[name=chapnav]')->find('option')->count();
if ($numChapters > 0) {
$story->chapters = $numChapters;
} else {
throw new FicSaveException("Could not get number of chapters for story at {$url}.");
}
return $story;
} else {
throw new FicSaveException("URL has an invalid story ID: {$storyId}.");
}
} else {
throw new FicSaveException("URL is missing story ID.");
}
}
示例10: facebookConnect
function facebookConnect($EMAIL, $PASSWORD)
{
$cookie = "";
//incorrect username and password here, we just want cookie data.
$a = cURL("https://login.facebook.com/login.php?login_attempt=1", true, null, "email=steve@apple.com&pass=ipod");
preg_match('%Set-Cookie: ([^;]+);%', $a, $b);
if (count($b) == 0) {
echo "Cookie phase one failed.";
die;
}
$c = cURL("https://login.facebook.com/login.php?login_attempt=1", true, $b[1], "email={$EMAIL}&pass={$PASSWORD}");
$fail = strpos($c, "Your account has a high number of invalid login attempts.");
if ($fail !== false) {
echo "Failed due to password abuse.";
die;
}
preg_match_all('%Set-Cookie: ([^;]+);%', $c, $d);
for ($i = 0; $i < count($d[0]); $i++) {
$cookie .= $d[1][$i] . ";";
}
return $cookie;
}
示例11: Login
private function Login()
{
if (!empty($_REQUEST['pA_encrypted']) && !empty($_REQUEST['premium_user']) && !empty($_REQUEST['premium_pass'])) {
$_REQUEST['premium_user'] = decrypt(urldecode($_REQUEST['premium_user']));
$_REQUEST['premium_pass'] = decrypt(urldecode($_REQUEST['premium_pass']));
unset($_REQUEST['pA_encrypted']);
}
$pA = empty($_REQUEST['premium_user']) || empty($_REQUEST['premium_pass']) ? false : true;
$user = $pA ? $_REQUEST['premium_user'] : $GLOBALS['premium_acc']['rapidgator_net']['user'];
$pass = $pA ? $_REQUEST['premium_pass'] : $GLOBALS['premium_acc']['rapidgator_net']['pass'];
if (empty($user) || empty($pass)) {
html_error('Login Failed: User or Password is empty. Please check login data.', 0);
}
$this->cookie = array('lang' => 'en');
// Account is always showed as free if it comes from a file, as i don't send file's link as referer, lets reset the cookies.
$post = array();
$post['LoginForm%5Bemail%5D'] = urlencode($user);
$post['LoginForm%5Bpassword%5D'] = urlencode($pass);
$post['LoginForm%5BrememberMe%5D'] = '1';
if (!empty($_POST['step']) && $_POST['step'] == '1') {
if (empty($_POST['captcha'])) {
html_error('You didn\'t enter the image verification code.');
}
$this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
$post['LoginForm%5BverifyCode%5D'] = urlencode($_POST['captcha']);
}
$purl = 'http://rapidgator.net/';
// There are more of those redirects at login
$rdc = 0;
$page = false;
// False value for starting the loop.
$redir = $purl . 'auth/login';
$this->referer = !empty($GLOBALS['Referer']) && $GLOBALS['Referer'] != $this->link ? $GLOBALS['Referer'] : $purl;
while (($redir = $this->ChkRGRedirs($page, $redir, '(?:/auth/login|/site/ChangeLocation/key/)')) && $rdc < 15) {
$page = cURL($redir, $this->cookie, $post, $this->referer);
$this->cookie = GetCookiesArr($page, $this->cookie);
$this->referer = $redir;
$rdc++;
}
is_present($page, 'Error e-mail or password.', 'Login Failed: Email/Password incorrect.');
is_present($page, 'E-mail is not a valid email address.', 'Login Failed: Login isn\'t an email address.');
is_present($page, 'We discovered that you try to access your account from unusual location.', 'Login Failed: Login Blocked By IP, Check Account Email And Follow The Steps To Add IP to Whitelist.');
if (stripos($page, 'The code from a picture does not coincide') !== false) {
if (!empty($_POST['step']) && $_POST['step'] == '1') {
html_error('Login Failed: Incorrect CAPTCHA response.');
}
if (!preg_match('@(https?://(?:[^\\./\\r\\n\'\\"\\t\\:]+\\.)?rapidgator\\.net(?:\\:\\d+)?)?/auth/captcha/\\w+/\\w+@i', $page, $imgurl)) {
html_error('Error: CAPTCHA not found.');
}
$imgurl = empty($imgurl[1]) ? 'http://rapidgator.net' . $imgurl[0] : $imgurl[0];
//Download captcha img.
$capt_page = cURL($imgurl, $this->cookie);
$capt_img = substr($capt_page, strpos($capt_page, "\r\n\r\n") + 4);
$imgfile = DOWNLOAD_DIR . 'rapidgator_captcha.png';
if (file_exists($imgfile)) {
unlink($imgfile);
}
if (!write_file($imgfile, $capt_img)) {
html_error('Error getting CAPTCHA image.');
}
unset($capt_page, $capt_img);
$data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
$data['step'] = '1';
$data['premium_acc'] = 'on';
// I should add 'premium_acc' to DefaultParamArr()
if ($pA) {
$data['pA_encrypted'] = 'true';
$data['premium_user'] = urlencode(encrypt($user));
// encrypt() will keep this safe.
$data['premium_pass'] = urlencode(encrypt($pass));
// And this too.
}
$this->EnterCaptcha($imgfile . '?' . time(), $data);
exit;
}
//is_present($page, 'The code from a picture does not coincide', 'Login Failed: Captcha... (T8: I will add it later)');
if (empty($this->cookie['user__'])) {
html_error("Login Error: Cannot find 'user__' cookie.");
}
$this->cookie['lang'] = 'en';
$page = cURL($purl, $this->cookie, 0, $purl . 'auth/login');
is_present($page, '>Free</a>', 'Account isn\'t premium');
$this->PremiumDL();
}
示例12: getStorage
function getStorage($storageNum)
{
$url = "http://www.blood.org.tw/Internet/main/index.aspx";
$response = cURL($url, '');
$html = str_get_html($response);
$res = $html->find('div[id=tool_blood_cube]', 0)->find('div[class=Storage]');
$data = array();
foreach ($res as $key => $value) {
if ($storageNum == $key || $storageNum == -1) {
$row = array();
$row['region'] = $value->find('div[id=StorageHeader]', 0)->plaintext;
$temp = $value->find('div', 1)->find('div');
foreach ($temp as $key1 => $blood) {
$id = $blood->getAttribute('id');
$type = $blood->find('img', 0)->getAttribute('alt');
switch ($type) {
case '庫存量7日以上':
$row[$id] = 3;
break;
case '庫存量4到7日':
$row[$id] = 2;
break;
case '庫存量4日以下':
$row[$id] = 1;
break;
default:
$row[$id] = 0;
break;
}
}
array_push($data, $row);
}
}
// echo "<pre>";
// print_r($data);
// echo "</pre>";
// // echo "$res";
return $data;
}
示例13: set_time_limit
//storageA
//storageB
//storageAB
//storageO
set_time_limit(0);
header("Content-Type:text/html; charset=utf-8");
require_once 'simple_html_dom.php';
$link = mysqli_connect('localhost', 'client', '1qaz2wsx', 'blood');
mysqli_query($link, "SET NAMES 'UTF8'");
$url = "http://www.blood.org.tw/Internet/main/map.aspx";
$length = 5;
$data = array();
for ($i = 1; $i < $length; $i++) {
$row = array();
$response = cURL($url . '?spotID=' . $i, '');
$html = str_get_html($response);
$res = $html->find('td[id=date_place]', 0)->plaintext;
if (trim($res) != "") {
$row['name'] = trim($res);
$res = $html->find('table[id=map_ifrom]', 0)->find('tr');
foreach ($res as $key => $value) {
$text = $value->find('td', 1)->plaintext;
array_push($row, trim($text));
}
$text = explode('(', trim($row['name']));
$row['name'] = $text[0];
if (isset($text[1])) {
$row[3] .= '<br>' . explode(')', $text[1])[0];
}
$text = explode('(', trim($row[0]));
示例14: saveItemData
/**
* Retrieve even more specific Item-Data and store them. See above, "saveItems"
* @param $db - Database
*/
function saveItemData($db)
{
global $apiKey;
$arr = json_decode(cURL("https://global.api.pvp.net/api/lol/static-data/euw/v1.2/item?itemListData=from,into,tags&api_key=" . $apiKey), true);
foreach ($arr["data"] as $val) {
if (!empty($val["tags"])) {
prettyPrint($val["tags"]);
foreach ($val["tags"] as $tag) {
$stmt = $db->mysqli->prepare("INSERT INTO `ItemTags` (`ItemID`, `Tag`) VALUES (?, ?)");
$stmt->bind_param("is", $val["id"], $tag);
$stmt->execute();
$stmt->close();
}
}
if (!empty($val["from"])) {
foreach ($val["from"] as $from) {
$stmt = $db->mysqli->prepare("INSERT INTO `ItemBuildsFrom` (`ItemID`, `BuildsFromID`) VALUES (?, ?)");
$stmt->bind_param("is", $val["id"], $from);
$stmt->execute();
$stmt->close();
}
}
if (!empty($val["into"])) {
foreach ($val["into"] as $into) {
$stmt = $db->mysqli->prepare("INSERT INTO `ItemBuildsInto` (`ItemID`, `BuildsIntoID`) VALUES (?, ?)");
$stmt->bind_param("is", $val["id"], $into);
$stmt->execute();
$stmt->close();
}
}
}
}
示例15: parse_url
$story["debug"] = false;
$cookies = "";
$parse = parse_url($story["story_url"]);
$domain = $parse["host"];
if (strpos($domain, "fanfiction.net") !== false || strpos($domain, "fictionpress.com") !== false) {
include_once "include/fanfiction_net.php";
} else {
if (strpos($domain, "adult-fanfiction.org") !== false) {
$host = explode('.', $parse['host']);
$subdomain = $host[0];
$cookies = "HasVisited=bypass page next time; path=/; domain={$subdomain}.adult-fanfiction.org";
include_once "include/adultfanfiction_org.php";
}
}
$dom = new DOMDocument();
$dom->loadHTML(cURL($story["story_url"], $story["debug"], $cookies, $uniqid));
$xpath = new DOMXPath($dom);
try {
$story = getStoryAttributes($xpath, $story);
} catch (WrongFormatException $ex) {
error_log("" . $ex);
echo "error";
exit(0);
}
$numChapter = $story["numChapter"];
// ========== CREATE EBOOK ========== //
$content_start = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" . " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" . "<head>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" . "<title>" . $story["title"] . "</title>\n" . "<style>.coverPage { text-align: center; height: 100%; width: 100%; }</style>\n" . "</head>\n" . "<body>\n";
$bookEnd = "</body>\n</html>\n";
if ($format == "pdf") {
require_once "pdf/tcpdf.php";
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);