本文整理汇总了PHP中core::gpc方法的典型用法代码示例。如果您正苦于以下问题:PHP core::gpc方法的具体用法?PHP core::gpc怎么用?PHP core::gpc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core
的用法示例。
在下文中一共展示了core::gpc方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: message
public function message($msg, $jumpurl = '')
{
if (core::gpc('ajax')) {
$arr = array('servererror' => '', 'status' => 1, 'message' => $msg);
echo core::json_encode($arr);
exit;
} else {
echo $msg;
exit;
}
}
示例2: display
public function display($file, $json = array())
{
if (!core::gpc('ajax', 'R')) {
extract($this->vars, EXTR_SKIP);
include $this->gettpl($file);
// json 格式,约定为格式。
} else {
ob_start();
extract($this->vars, EXTR_SKIP);
include $this->gettpl($file);
$body = ob_get_contents();
ob_end_clean();
$json = array('servererror' => '', 'status' => 1, 'message' => array('width' => 400, 'height' => 300, 'pos' => 'center', 'title' => '默认窗口标题', 'body' => ''));
$json['message'] = array_merge($json['message'], $this->json);
$this->fetch_json_header($body, $json['message']);
$json['message']['body'] = $body;
echo core::json_encode($json);
}
}
示例3: rand_name
public static function rand_name($k)
{
return core::gpc('time', 'S') . '_' . rand(1000000000, 9999999999) . '_' . $k;
}
示例4: format_exception
<?php
/*
* XiunoPHP v1.2
* http://www.xiuno.com/
*
* Copyright 2010 (c) axiuno@gmail.com
* GNU LESSER GENERAL PUBLIC LICENSE Version 3
* http://www.gnu.org/licenses/lgpl.html
*
*/
if (empty($_SERVER['ip'])) {
$_SERVER['ip'] = core::gpc('REMOTE_ADDR', 'S');
}
if (empty($_SERVER['time'])) {
$_SERVER['time'] = time();
}
// 仅仅用来显示 Exception
class xn_exception
{
/*
// 异常CODE,用来标示是哪个模块产生的异常。暂时不需要。
const APP_EXCEPTION_CODE_ERROR_HANDLE = 1;
const APP_EXCEPTION_CODE_MYSQL = 2;
const APP_EXCEPTION_CODE_LOG = 3;
*/
public static function format_exception($e)
{
$trace = $e->getTrace();
// 如果是 error_handle ,弹出第一个元素。
if (!empty($trace) && $trace[0]['function'] == 'error_handle' && $trace[0]['class'] == 'core') {
示例5: ob_handle
public static function ob_handle($s)
{
if (!empty($_SERVER['ob_stack'])) {
$gzipon = array_pop($_SERVER['ob_stack']);
} else {
// throw new Exception('');
$gzipon = 0;
}
$isfirst = count($_SERVER['ob_stack']) == 0;
if ($gzipon && !ini_get('zlib.output_compression') && function_exists('gzencode') && strpos(core::gpc('HTTP_ACCEPT_ENCODING', 'S'), 'gzip') !== FALSE) {
$s = gzencode($s, 5);
// 0 - 9 级别, 9 最小,最耗费 CPU
$isfirst && header("Content-Encoding: gzip");
//$isfirst && header("Vary: Accept-Encoding"); // 下载的时候,IE 6 会直接输出脚本名,而不是文件名!非常诡异!估计是压缩标志混乱。
$isfirst && header("Content-Length: " . strlen($s));
} else {
// PHP 强制发送的 gzip 头
if (ini_get('zlib.output_compression')) {
$isfirst && header("Content-Encoding: gzip");
} else {
$isfirst && header("Content-Encoding: none");
$isfirst && header("Content-Length: " . strlen($s));
}
}
return $s;
}
示例6: run
public static function run(&$conf)
{
//----------------------------------> 包含相关的 control,并实例化
$control = core::gpc(0);
$action = core::gpc(1);
$objfile = $conf['tmp_path'] . $conf['app_id'] . "_control_{$control}_control.class.php";
// 如果缓存文件不存在,则搜索目录
if (!is_file($objfile) || DEBUG > 0 && !IN_SAE) {
$controlfile = '';
if (empty($conf['plugin_disable'])) {
$plugins = core::get_enable_plugins($conf);
$pluginnames = array_keys($plugins);
foreach ($pluginnames as $v) {
// 如果有相关的 app path, 这只读取该目录, plugin/xxx/abc_control.class.php, plugin/xxx/admin/abc_control.class.php
$path = $conf['plugin_path'] . $v . '/';
if (is_file($path . $conf['app_id'] . '/' . "{$control}_control.class.php")) {
$controlfile = $path . $conf['app_id'] . '/' . "{$control}_control.class.php";
break;
}
if (is_file($path . "{$control}_control.class.php")) {
$controlfile = $path . "{$control}_control.class.php";
break;
} else {
$controlfile = '';
}
}
}
if (empty($controlfile)) {
$paths = $conf['control_path'];
foreach ($paths as $path) {
$controlfile = $path . "{$control}_control.class.php";
if (is_file($controlfile)) {
break;
} else {
$controlfile = '';
}
}
}
if (empty($controlfile)) {
throw new Exception("您输入的URL 不合法,{$control} control 不存在。");
}
// 处理 hook urlrewrite, static_url
if (!is_file($controlfile)) {
throw new Exception("您输入的URL 不合法,{$control} control 不存在。");
}
$s = file_get_contents($controlfile);
core::process_include($conf, $s);
$_ENV['preg_replace_callback_arg'] = $conf;
$s = preg_replace_callback('#\\t*\\/\\/\\s*hook\\s+([^\\s]+)#is', 'core::process_hook_callback', $s);
core::process_urlrewrite($conf, $s);
file_put_contents($objfile, $s);
}
if (include $objfile) {
$controlclass = "{$control}_control";
$onaction = "on_{$action}";
$newcontrol = new $controlclass($conf);
if (method_exists($newcontrol, $onaction)) {
$newcontrol->{$onaction}();
} else {
throw new Exception("您输入的URL 不合法,{$action} 方法未实现:");
}
} else {
throw new Exception("您输入的URL 不合法,{$control} control 不存在。");
}
unset($newcontrol, $control, $action);
}
示例7: error_handler
/**
* Custom error handler.
*
* Catches all errors (not exceptions) and creates an ErrorException.
* ErrorException then can caught by Yaf\ErrorController.
*
* @param integer $errno the error number.
* @param string $errstr the error message.
* @param string $errfile the file where error occured.
* @param integer $errline the line of the file where error occured.
*
* @throws ErrorException
*/
static function error_handler($errno, $errstr, $errfile, $errline)
{
// 防止死循环
$errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice');
$errnostr = isset($errortype[$errno]) ? $errortype[$errno] : 'Unknonw';
// 运行时致命错误,直接退出。并且 debug_backtrace()
$s = "[{$errnostr}] : {$errstr} in File {$errfile}, Line: {$errline}";
// 抛出异常,记录到日志
//echo $errstr;
if (DEBUG && empty($_SERVER['exception'])) {
throw new Exception($s);
} else {
log::write($s . date('Y-M-D H:i:s', $_SERVER['time']));
//$s = preg_replace('# \S*[/\\\\](.+?\.php)#', ' \\1', $s);
if (core::gpc('ajax', 'R')) {
core::ob_clean();
//$s = preg_replace('#[\\x80-\\xff]{2}#', '?', $s);// 替换掉 gbk, 否则 json_encode 会报错!
// 判断错误级别,决定是否退出。
if ($errno != E_NOTICE && $errno != E_USER_ERROR && $errno != E_USER_NOTICE && $errno != E_USER_WARNING) {
$s = core::json_encode(array('servererror' => $s));
throw new Exception($s);
exit;
} else {
$_SERVER['notice_error'] .= $s;
// 继续执行。
}
} else {
//echo $s;
// 继续执行。
}
}
return 0;
}
示例8: get_script_uri
public static function get_script_uri()
{
$port = core::gpc('SERVER_PORT', 'S');
//$portadd = $port == 80 ? '' : ':80';
$host = core::gpc('HTTP_HOST', 'S');
//$schme = self::gpc('SERVER_PROTOCOL', 'S');
// [SERVER_SOFTWARE] => Microsoft-IIS/6.0
// [REQUEST_URI] => /index.php
// [HTTP_X_REWRITE_URL] => /?a=b
// iis
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$request_uri = $_SERVER['HTTP_X_REWRITE_URL'];
} else {
$request_uri = $_SERVER['REQUEST_URI'];
}
return "http://{$host}" . $request_uri;
//if(isset($_SERVER['SCRIPT_URI']) && 0) {
// return $_SERVER['SCRIPT_URI'];// 会漏掉 query_string, .core::gpc('QUERY_STRING', 'S');
//}
}
示例9: fetch_url
public static function fetch_url($url, $timeout = 10, $post = '', $cookie = '', $deep = 0)
{
if ($deep > 5) {
throw new Exception('超出 fetch_url() 最大递归深度!');
}
if (substr($url, 0, 5) == 'https') {
return self::https_fetch_url($url, $timeout, $post, $cookie, $deep);
}
$w = stream_get_wrappers();
$allow_url_fopen = strtolower(ini_get('allow_url_fopen'));
$allow_url_fopen = empty($allow_url_fopen) || $allow_url_fopen == 'off' ? 0 : 1;
if (function_exists('fsockopen')) {
$limit = 2000000;
$ip = '';
$return = '';
$matches = parse_url($url);
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'] . (!empty($matches['query']) ? '?' . $matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
$HTTP_USER_AGENT = core::gpc('$HTTP_USER_AGENT', 'S');
empty($HTTP_USER_AGENT) && ($HTTP_USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)');
if (empty($post)) {
$out = "GET {$path} HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: {$HTTP_USER_AGENT}\r\n";
$out .= "Host: {$host}\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie:{$cookie}\r\n\r\n";
} else {
$out = "POST {$path} HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: {$HTTP_USER_AGENT}\r\n";
$out .= "Host: {$host}\r\n";
$out .= 'Content-Length: ' . strlen($post) . "\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-cache\r\n";
$out .= "Cookie:{$cookie}\r\n\r\n";
$out .= $post;
}
$host == 'localhost' && ($ip = '127.0.0.1');
$fp = @fsockopen($ip ? $ip : $host, $port, $errno, $errstr, $timeout);
if (!$fp) {
return FALSE;
} else {
stream_set_blocking($fp, TRUE);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $out);
$status = stream_get_meta_data($fp);
if (!$status['timed_out']) {
$starttime = time();
while (!feof($fp)) {
if (($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
//Location: http://plugin.xiuno.net/upload/plugin/66/b0c35647c63b8b880766b50c06586c13.zip
} else {
if (strtolower(substr($header, 0, 9)) == 'location:') {
$location = trim(substr($header, 9));
return self::fetch_url($location, $timeout, $post, $cookie, $deep + 1);
}
}
}
$stop = false;
while (!feof($fp) && !$stop) {
$data = fread($fp, $limit == 0 || $limit > 8192 ? 8192 : $limit);
$return .= $data;
if ($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
if (time() - $starttime > $timeout) {
break;
}
}
}
@fclose($fp);
return $return;
}
} elseif (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie', $cookie));
}
$data = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Errno' . curl_error($ch));
//捕抓异常
}
if (!$data) {
curl_close($ch);
return '';
//.........这里部分代码省略.........
示例10: is_robot
public static function is_robot()
{
$robots = array('robot', 'spider', 'slurp');
foreach ($robots as $robot) {
if (strpos(core::gpc('HTTP_USER_AGENT', 'S'), $robot) !== FALSE) {
return TRUE;
}
}
return FALSE;
}