本文整理汇总了PHP中HTTP类的典型用法代码示例。如果您正苦于以下问题:PHP HTTP类的具体用法?PHP HTTP怎么用?PHP HTTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _xUpdateGetInstaller
function _xUpdateGetInstaller()
{
global $C;
$post_data = array('upgrade' => true, 'version' => $_REQUEST['version'], 'key' => LIC_KEY, 'domain' => domain_from_url($C['base_url']));
require_once 'http.php';
$http = new HTTP();
if ($http->POST(URL_DOWNLOAD, $post_data)) {
if (preg_match('~X-SHA1: ([a-z0-9]+)~i', $http->response_headers, $matches)) {
$installer_file = DIR_DATA . '/install.dat';
$sha1 = $matches[1];
file_write($installer_file, $http->body);
if ($sha1 != sha1_file($installer_file)) {
file_delete($installer_file);
JSON::Error('File hash does not match, possible corrupted data. Please try again.');
} else {
JSON::Success();
}
} else {
if (preg_match('~X-Error: ([a-z0-9_]+)~i', $http->response_headers, $matches)) {
JSON::Error('Unable to locate a license for this domain');
} else {
JSON::Error('Download from jmbsoft.com failed, please try again');
}
}
} else {
JSON::Error('Unable to connect to jmbsoft.com for update: ' + $http->error);
}
}
示例2: _execute
private static function _execute($url, $method, $post = null)
{
$data = parse_url($url);
if (isset($data['user']) || isset($data['pass'])) {
// TODO: not yet implemented
return false;
}
if (isset($data['query'])) {
$data['fullpath'] = $data['path'] . '?' . $data['query'];
} else {
$data['fullpath'] = $data['path'];
}
switch ($data['scheme']) {
case 'http':
$HTTP = new HTTP($data['host'], isset($data['port']) ? $data['port'] : 80);
break;
case 'https':
$HTTP = new HTTP($data['host'], isset($data['port']) ? $data['port'] : 443, true);
break;
default:
return false;
break;
}
switch ($method) {
case 'GET':
return $HTTP->GET($data['fullpath']);
break;
case 'POST':
return $HTTP->POST($data['fullpath'], $post);
break;
default:
return false;
break;
}
}
示例3: fetchFunctionDescription
private function fetchFunctionDescription($func)
{
$HTTP = new HTTP('php.net');
$html = $HTTP->GET('/' . $this->getConfig('language') . '/' . $func);
if ($html === false) {
$this->reply('Timeout on contacting ' . $host);
return;
}
if (preg_match('/<span class=\\"refname\\">(.*?)<\\/span> — <span class=\\"dc\\-title\\">(.*?)<\\/span>/si', $html, $match)) {
$match[2] = str_replace(array("\n", "\r"), ' ', strip_tags($match[2]));
preg_match('/<div class=\\"methodsynopsis dc\\-description\\">(.*?)<\\/div>/si', $html, $descmatch);
$decl = isset($descmatch[1]) ? strip_tags($descmatch[1]) : $match[1];
$decl = html_entity_decode(str_replace(array("\n", "\r"), ' ', $decl));
while (strstr($decl, ' ')) {
$decl = str_replace(' ', ' ', $decl);
}
$decl = str_replace($func, "" . $func . "", $decl);
$output = $decl . ' - ' . html_entity_decode($match[2]) . ' ( http://php.net/' . $func . ' )';
$this->reply(libString::isUTF8($output) ? $output : utf8_encode($output));
} else {
// if several possibilities
$output = '';
if (preg_match_all('/<a href=\\"\\/manual\\/[a-z]+\\/(?:.*?)\\.php\\">(?:<b>)?(.*?)(?:<\\/b>)?<\\/a><br/i', $html, $matches, PREG_SET_ORDER)) {
if ($this->redirects++ < 2) {
$this->fetchFunctionDescription($matches[0][1]);
} else {
$this->reply($this->notfoundtext . ' http://php.net/search.php?show=wholesite&pattern=' . $this->data['text']);
}
return;
} else {
$output = $this->notfoundtext . ' http://php.net/search.php?show=wholesite&pattern=' . $func;
}
$this->reply(libString::isUTF8($output) ? $output : utf8_encode($output));
}
}
示例4: tinyURLDecode
static function tinyURLDecode($tinyurl)
{
$parts = parse_url($tinyurl);
$HTTP = new HTTP('tinyurl.com');
$HTTP->set('auto-follow', false);
$HTTP->GET($parts['path']);
$header = $HTTP->getHeader();
if (!isset($header['Location'])) {
return false;
}
return $header['Location'];
}
示例5: __construct
public function __construct()
{
$pgHTTP = new HTTP();
$text = $pgHTTP->get('http://meta.wikimedia.org/w/index.php?title=IRC/Quotes&action=raw&ctype=text/css', false);
$text = explode('<pre><nowiki>', $text);
$text = explode('</nowiki></pre>', $text[1]);
$text = explode('%%', $text[0]);
$text = substr($text[0], 2);
$text = htmlspecialchars($text);
$text = trim($text);
$text = preg_replace('/\\n/', '<br />', $text);
$this->quotes = explode("%<br />", $text);
}
示例6: isTriggered
function isTriggered()
{
if (!isset($this->data['text'])) {
$this->printUsage();
return;
}
$HTTP = new HTTP('api.themoviedb.org');
$html = $HTTP->GET('/2.1/Movie.search/' . $this->getConfig('language') . '/xml/' . $this->api_key . '/' . urlencode($this->data['text']));
$XML = simplexml_load_string($html);
if (!$XML) {
$this->reply('Error on contacting themoviedb.org');
return;
}
$tmp = $XML->xpath('opensearch:totalResults');
$results = (int) $tmp[0];
if (!$results) {
if ($this->getConfig('language') != 'en') {
$html = $HTTP->GET('/2.1/Movie.search/en/xml/' . $this->api_key . '/' . urlencode($this->data['text']));
$XML = new SimpleXMLElement($html);
if (!$XML) {
$this->reply('Error on contacting themoviedb.org');
return;
}
$tmp = $XML->xpath('opensearch:totalResults');
$results = (int) $tmp[0];
}
}
if (!$results) {
$this->reply('There is no information available about this movie.');
return;
}
$tmp = $XML->children()->children();
$Movie = $tmp[0];
$text = "" . $Movie->name . "";
if ((string) $Movie->original_name != (string) $Movie->name) {
$text .= ' (' . $Movie->original_name . ')';
}
if (!empty($Movie->released)) {
$text .= " | Released: " . $Movie->released;
}
if ($Movie->rating != '0.0') {
$text .= " | Press Rating: " . $Movie->rating . '/10';
}
if (!empty($Movie->certification)) {
$text .= " | Rated: " . $Movie->certification;
}
$text .= ' (' . $Movie->url . ')';
$this->reply($text);
$this->reply($Movie->overview);
}
示例7: setup
public function setup()
{
if (get_setting('index_per_page')) {
$this->per_page = get_setting('index_per_page');
}
HTTP::no_cache_header();
}
示例8: action_logout
/**
*
*/
public function action_logout()
{
if (!\Registry::getCurrentUser()->isGuest()) {
\Auth\Base::destroy();
}
\HTTP::redirect(\Route::get('SystemRoute')->uri(['controller' => 'Main', 'action' => 'Login']), 302);
}
示例9: Execute
function Execute()
{
require_once 'http.php';
$http = new HTTP();
if ($http->POST($this->url, $this->post_data)) {
if (strpos($http->body, NETWORK_SUCCESS) === 0) {
return substr($http->body, strlen(NETWORK_SUCCESS));
} else {
$this->error = substr(strip_tags($http->body), 0, 100);
return false;
}
} else {
$this->error = $http->error;
return false;
}
}
示例10: sendFile
/**
* Output file to the browser.
* For performance reasons, we avoid SS_HTTPResponse and just output the contents instead.
*/
public function sendFile($file)
{
$path = $file->getFullPath();
if (SapphireTest::is_running_test()) {
return file_get_contents($path);
}
header('Content-Description: File Transfer');
// Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)
header('Content-Disposition: inline; filename="' . basename($path) . '"');
header('Content-Length: ' . $file->getAbsoluteSize());
header('Content-Type: ' . HTTP::get_mime_type($file->getRelativePath()));
header('Content-Transfer-Encoding: binary');
// Fixes IE6,7,8 file downloads over HTTPS bug (http://support.microsoft.com/kb/812935)
header('Pragma: ');
if ($this->config()->min_download_bandwidth) {
// Allow the download to last long enough to allow full download with min_download_bandwidth connection.
increase_time_limit_to((int) (filesize($path) / ($this->config()->min_download_bandwidth * 1024)));
} else {
// Remove the timelimit.
increase_time_limit_to(0);
}
// Clear PHP buffer, otherwise the script will try to allocate memory for entire file.
while (ob_get_level() > 0) {
ob_end_flush();
}
// Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same
// website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/)
session_write_close();
readfile($path);
die;
}
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce-downloadableproduct,代码行数:35,代码来源:DownloadableFileController.php
示例11: buy
function buy()
{
global $USER, $LNG, $THEME, $UNI;
$days = HTTP::_GP('hide', 1);
if ($days == 1) {
if ($USER['planet_cloak_countdown'] > TIMESTAMP) {
$this->printMessage($LNG['planetcloak_cntdown'], true, array('game.php?page=overview', 2));
} elseif ($USER['darkmatter'] < 500000) {
$this->printMessage($LNG['gover_notres'], true, array('game.php?page=overview', 2));
} else {
$USER['darkmatter'] -= 500000;
$GLOBALS['DATABASE']->query("Update " . USERS . " SET `planet_cloak` = " . (TIMESTAMP + 3 * 24 * 60 * 60) . " WHERE `id` = " . $USER['id'] . " AND universe = " . $UNI . ";");
$GLOBALS['DATABASE']->query("Update " . USERS . " SET `planet_cloak_countdown` = " . (TIMESTAMP + 11 * 24 * 60 * 60) . " WHERE `id` = " . $USER['id'] . " AND universe = " . $UNI . ";");
$GLOBALS['DATABASE']->query("INSERT INTO uni1_planetcloak_log VALUES ('" . $GLOBALS['DATABASE']->GetInsertID() . "','" . $USER['id'] . "','" . TIMESTAMP . "','20000');");
$this->printMessage($LNG['planetcloak_activate_one'], true, array('game.php?page=overview', 2));
}
} elseif ($days == 2) {
if ($USER['planet_cloak_countdown'] > TIMESTAMP) {
$this->printMessage($LNG['planetcloak_cntdown'], true, array('game.php?page=overview', 2));
} elseif ($USER['darkmatter'] < 2000000) {
$this->printMessage($LNG['gover_notres'], true, array('game.php?page=overview', 2));
} else {
$USER['darkmatter'] -= 2000000;
$GLOBALS['DATABASE']->query("Update " . USERS . " SET `planet_cloak` = " . (TIMESTAMP + 14 * 24 * 60 * 60) . " WHERE `id` = " . $USER['id'] . " AND universe = " . $UNI . ";");
$GLOBALS['DATABASE']->query("Update " . USERS . " SET `planet_cloak_countdown` = " . (TIMESTAMP + 44 * 24 * 60 * 60) . " WHERE `id` = " . $USER['id'] . " AND universe = " . $UNI . ";");
$GLOBALS['DATABASE']->query("INSERT INTO uni1_planetcloak_log VALUES ('" . $GLOBALS['DATABASE']->GetInsertID() . "','" . $USER['id'] . "','" . TIMESTAMP . "','100000');");
$this->printMessage($LNG['planetcloak_activate_seven'], true, array('game.php?page=overview', 2));
}
}
$this->tplObj->assign_vars(array());
$this->display('page.planetcloak.default.tpl');
}
示例12: show
function show()
{
if (empty($_POST)) {
HTTP::redirectTo('index.php');
}
$db = Database::get();
$username = HTTP::_GP('username', '', UTF8_SUPPORT);
$password = HTTP::_GP('password', '', true);
$sql = "SELECT id, password FROM %%USERS%% WHERE universe = :universe AND username = :username;";
$loginData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':username' => $username));
if (isset($loginData)) {
$hashedPassword = PlayerUtil::cryptPassword($password);
if ($loginData['password'] != $hashedPassword) {
// Fallback pre 1.7
if ($loginData['password'] == md5($password)) {
$sql = "UPDATE %%USERS%% SET password = :hashedPassword WHERE id = :loginID;";
$db->update($sql, array(':hashedPassword' => $hashedPassword, ':loginID' => $loginData['id']));
} else {
HTTP::redirectTo('index.php?code=1');
}
}
$session = Session::create();
$session->userId = (int) $loginData['id'];
$session->adminAccess = 0;
$session->save();
HTTP::redirectTo('game.php');
} else {
HTTP::redirectTo('index.php?code=1');
}
}
示例13: ShowChatConfigPage
function ShowChatConfigPage()
{
global $LNG;
$config = Config::get(Universe::getEmulated());
if (!empty($_POST)) {
$config_before = array('chat_closed' => $config->chat_closed, 'chat_allowchan' => $config->chat_allowchan, 'chat_allowmes' => $config->chat_allowmes, 'chat_allowdelmes' => $config->chat_allowdelmes, 'chat_logmessage' => $config->chat_logmessage, 'chat_nickchange' => $config->chat_nickchange, 'chat_botname' => $config->chat_botname, 'chat_channelname' => $config->chat_channelname);
$chat_allowchan = isset($_POST['chat_allowchan']) && $_POST['chat_allowchan'] == 'on' ? 1 : 0;
$chat_allowmes = isset($_POST['chat_allowmes']) && $_POST['chat_allowmes'] == 'on' ? 1 : 0;
$chat_allowdelmes = isset($_POST['chat_allowdelmes']) && $_POST['chat_allowdelmes'] == 'on' ? 1 : 0;
$chat_logmessage = isset($_POST['chat_logmessage']) && $_POST['chat_logmessage'] == 'on' ? 1 : 0;
$chat_nickchange = isset($_POST['chat_nickchange']) && $_POST['chat_nickchange'] == 'on' ? 1 : 0;
$chat_closed = isset($_POST['chat_closed']) && $_POST['chat_closed'] == 'on' ? 1 : 0;
$chat_channelname = HTTP::_GP('chat_channelname', '', true);
$chat_botname = HTTP::_GP('chat_botname', '', true);
$config_after = array('chat_closed' => $chat_closed, 'chat_allowchan' => $chat_allowchan, 'chat_allowmes' => $chat_allowmes, 'chat_allowdelmes' => $chat_allowdelmes, 'chat_logmessage' => $chat_logmessage, 'chat_nickchange' => $chat_nickchange, 'chat_botname' => $chat_botname, 'chat_channelname' => $chat_channelname);
foreach ($config_after as $key => $value) {
$config->{$key} = $value;
}
$config->save();
$LOG = new Log(3);
$LOG->target = 3;
$LOG->old = $config_before;
$LOG->new = $config_after;
$LOG->save();
}
$template = new template();
$template->assign_vars(array('chat_closed' => $config->chat_closed, 'chat_allowchan' => $config->chat_allowchan, 'chat_allowmes' => $config->chat_allowmes, 'chat_logmessage' => $config->chat_logmessage, 'chat_nickchange' => $config->chat_nickchange, 'chat_botname' => $config->chat_botname, 'chat_channelname' => $config->chat_channelname, 'se_server_parameters' => $LNG['se_server_parameters'], 'se_save_parameters' => $LNG['se_save_parameters'], 'ch_closed' => $LNG['ch_closed'], 'ch_allowchan' => $LNG['ch_allowchan'], 'ch_allowmes' => $LNG['ch_allowmes'], 'ch_allowdelmes' => $LNG['ch_allowdelmes'], 'ch_logmessage' => $LNG['ch_logmessage'], 'ch_nickchange' => $LNG['ch_nickchange'], 'ch_botname' => $LNG['ch_botname'], 'ch_channelname' => $LNG['ch_channelname']));
$template->show('ChatConfigBody.tpl');
}
示例14: ShowFlyingFleetPage
function ShowFlyingFleetPage()
{
global $LNG;
$id = HTTP::_GP('id', 0);
if (!empty($id)) {
$lock = HTTP::_GP('lock', 0);
$GLOBALS['DATABASE']->query("UPDATE " . FLEETS . " SET `fleet_busy` = '" . $lock . "' WHERE `fleet_id` = '" . $id . "' AND `fleet_universe` = '" . Universe::getEmulated() . "';");
$SQL = $lock == 0 ? "NULL" : "'ADM_LOCK'";
$GLOBALS['DATABASE']->query("UPDATE " . FLEETS_EVENT . " SET `lock` = " . $SQL . " WHERE `fleetID` = " . $id . ";");
}
$orderBy = "fleet_id";
$fleetResult = $GLOBALS['DATABASE']->query("SELECT \n\tfleet.*,\n\tevent.`lock`,\n\tCOUNT(event.fleetID) as error,\n\tpstart.name as startPlanetName,\n\tptarget.name as targetPlanetName,\n\tustart.username as startUserName,\n\tutarget.username as targetUserName,\n\tacs.name as acsName\n\tFROM " . FLEETS . " fleet\n\tLEFT JOIN " . FLEETS_EVENT . " event ON fleetID = fleet_id\n\tLEFT JOIN " . PLANETS . " pstart ON pstart.id = fleet_start_id\n\tLEFT JOIN " . PLANETS . " ptarget ON ptarget.id = fleet_end_id\n\tLEFT JOIN " . USERS . " ustart ON ustart.id = fleet_owner\n\tLEFT JOIN " . USERS . " utarget ON utarget.id = fleet_target_owner\n\tLEFT JOIN " . AKS . " acs ON acs.id = fleet_group\n\tWHERE fleet_universe = " . Universe::getEmulated() . "\n\tGROUP BY event.fleetID\n\tORDER BY " . $orderBy . ";");
$FleetList = array();
while ($fleetRow = $GLOBALS['DATABASE']->fetch_array($fleetResult)) {
$shipList = array();
$shipArray = array_filter(explode(';', $fleetRow['fleet_array']));
foreach ($shipArray as $ship) {
$shipDetail = explode(',', $ship);
$shipList[$shipDetail[0]] = $shipDetail[1];
}
$FleetList[] = array('fleetID' => $fleetRow['fleet_id'], 'lock' => !empty($fleetRow['lock']), 'count' => $fleetRow['fleet_amount'], 'error' => !$fleetRow['error'], 'ships' => $shipList, 'state' => $fleetRow['fleet_mess'], 'starttime' => _date($LNG['php_tdformat'], $fleetRow['start_time'], $USER['timezone']), 'arrivaltime' => _date($LNG['php_tdformat'], $fleetRow['fleet_start_time'], $USER['timezone']), 'stayhour' => round(($fleetRow['fleet_end_stay'] - $fleetRow['fleet_start_time']) / 3600), 'staytime' => $fleetRow['fleet_start_time'] !== $fleetRow['fleet_end_stay'] ? _date($LNG['php_tdformat'], $fleetRow['fleet_end_stay'], $USER['timezone']) : 0, 'endtime' => _date($LNG['php_tdformat'], $fleetRow['fleet_end_time'], $USER['timezone']), 'missionID' => $fleetRow['fleet_mission'], 'acsID' => $fleetRow['fleet_group'], 'acsName' => $fleetRow['acsName'], 'startUserID' => $fleetRow['fleet_owner'], 'startUserName' => $fleetRow['startUserName'], 'startPlanetID' => $fleetRow['fleet_start_id'], 'startPlanetName' => $fleetRow['startPlanetName'], 'startPlanetGalaxy' => $fleetRow['fleet_start_galaxy'], 'startPlanetSystem' => $fleetRow['fleet_start_system'], 'startPlanetPlanet' => $fleetRow['fleet_start_planet'], 'startPlanetType' => $fleetRow['fleet_start_type'], 'targetUserID' => $fleetRow['fleet_target_owner'], 'targetUserName' => $fleetRow['targetUserName'], 'targetPlanetID' => $fleetRow['fleet_end_id'], 'targetPlanetName' => $fleetRow['targetPlanetName'], 'targetPlanetGalaxy' => $fleetRow['fleet_end_galaxy'], 'targetPlanetSystem' => $fleetRow['fleet_end_system'], 'targetPlanetPlanet' => $fleetRow['fleet_end_planet'], 'targetPlanetType' => $fleetRow['fleet_end_type'], 'resource' => array(901 => $fleetRow['fleet_resource_metal'], 902 => $fleetRow['fleet_resource_crystal'], 903 => $fleetRow['fleet_resource_deuterium'], 921 => $fleetRow['fleet_resource_darkmatter']));
}
$GLOBALS['DATABASE']->free_result($fleetResult);
$template = new template();
$template->assign_vars(array('FleetList' => $FleetList));
$template->show('FlyingFleetPage.tpl');
}
示例15: ShowDisclamerPage
function ShowDisclamerPage()
{
global $LNG;
$config = Config::get(Universe::getEmulated());
if (!empty($_POST)) {
$config_before = array('disclamerAddress' => $config->disclamerAddress, 'disclamerPhone' => $config->disclamerPhone, 'disclamerMail' => $config->disclamerMail, 'disclamerNotice' => $config->disclamerNotice);
$disclaimerAddress = HTTP::_GP('disclaimerAddress', '', true);
$disclaimerPhone = HTTP::_GP('disclaimerPhone', '', true);
$disclaimerMail = HTTP::_GP('disclaimerMail', '', true);
$disclaimerNotice = HTTP::_GP('disclaimerNotice', '', true);
$config_after = array('disclamerAddress' => $disclaimerAddress, 'disclamerPhone' => $disclaimerPhone, 'disclamerMail' => $disclaimerMail, 'disclamerNotice' => $disclaimerNotice);
foreach ($config_after as $key => $value) {
$config->{$key} = $value;
}
$config->save();
$LOG = new Log(3);
$LOG->target = 5;
$LOG->old = $config_before;
$LOG->new = $config_after;
$LOG->save();
}
$template = new template();
$template->loadscript('../base/jquery.autosize-min.js');
$template->execscript('$(\'textarea\').autosize();');
$template->assign_vars(array('disclaimerAddress' => $config->disclamerAddress, 'disclaimerPhone' => $config->disclamerPhone, 'disclaimerMail' => $config->disclamerMail, 'disclaimerNotice' => $config->disclamerNotice, 'se_server_parameters' => $LNG['mu_disclaimer'], 'se_save_parameters' => $LNG['se_save_parameters'], 'se_disclaimerAddress' => $LNG['se_disclaimerAddress'], 'se_disclaimerPhone' => $LNG['se_disclaimerPhone'], 'se_disclaimerMail' => $LNG['se_disclaimerMail'], 'se_disclaimerNotice' => $LNG['se_disclaimerNotice']));
$template->show('DisclamerConfigBody.tpl');
}