Heim > Backend-Entwicklung > PHP-Tutorial > zhphp-Framework drei Framework-Workflows

zhphp-Framework drei Framework-Workflows

WBOY
Freigeben: 2016-07-29 09:10:37
Original
1240 Leute haben es durchsucht
<?php
/**
 * Created by PhpStorm.
 * User:  张华
 * Date: 2015/8/27
 * Time: 1:12
 * * QQ: 746502560@qq.com
 * To change this template use File | Settings | File Templates.
 */
######################web run start#################################################
define(&#39;IN_ZHPHP&#39;, true);
define(&#39;FRAMEWORKNAME&#39;, &#39;ZHPHP&#39;);
define(&#39;VERSION&#39;, &#39;v2.1.3&#39;);
define(&#39;RELEASE&#39;, &#39;20151108&#39;);
$startTime=microtime(true);#开始计时
<strong>version_compare</strong>(PHP_VERSION, &#39;5.2&#39;, &#39;>=')?true:die('<lable style="color:#ff0000;">严重警告:php的版本低于php5.2!</lable>');#获取php版本并对php版本判断 Zhphp 框架最低ph版本为 php5.2
######################################## gzip compres start ############################################################
$HTTP_ACCEPT_ENCODING=$GLOBALS['_SERVER']['HTTP_ACCEPT_ENCODING'];
function CheckCanGzip(){#检测是否支持压缩
    global $HTTP_ACCEPT_ENCODING;
    if(!ini_get('zlib.output_compression')){#判断你是否配置php服务器压缩
        if(extension_loaded("zlib")){
            if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false){
                return "x-gzip";
            }else if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false){
                return "gzip";
            }
        }
    }
    return 0;
}
/**
 * 页面压缩后输出
 * @param $content
 * @return string
 */
function ob_gzlib($content){
    $ENCODING = CheckCanGzip();
    if($ENCODING){
        $content = gzencode($content,6);
        header("Content-Encoding: ".$ENCODING);
        header("Vary: Accept-Encoding");
        header("Content-Length: ".strlen($content));
        return $content;
    }
    return false;
}
###################################  stystem set define start ##########################################################
defined('APP_DEBUG')?APP_DEBUG:define('APP_DEBUG',false);#是否设为调试
defined('DS')?DS:define( 'DS' , DIRECTORY_SEPARATOR );#分割符号
defined('DOC_ROOT')?DOC_ROOT:define('DOC_ROOT',$GLOBALS['_SERVER']['DOCUMENT_ROOT']);#得到服务器根目录地址
defined('APP_NAME')?APP_NAME:define('APP_NAME','application');#默认工程名
$http_type = ((isset($GLOBALS['_SERVER']['']) && $GLOBALS['_SERVER']['HTTPS'] == 'on') || (isset($GLOBALS['_SERVER']['HTTP_X_FORWARDED_PROTO']) && $GLOBALS['_SERVER']['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$httpHost=isset($GLOBALS['_SERVER']['HTTP_HOST'])?$GLOBALS['_SERVER']['HTTP_HOST']:$_SERVER['HTTP_HOST'];
defined('CLASS_HTTP')?CLASS_HTTP:define('CLASS_HTTP',$http_type.$_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')));
$requestUri=isset($GLOBALS['_SERVER']['REQUEST_URI'])?$GLOBALS['_SERVER']['REQUEST_URI']:$_SERVER['REQUEST_URI'];
defined('HTTP')?HTTP:define('HTTP',$httpHost);
defined('APP_URI')?APP_URI:define('APP_URI',$http_type.$httpHost.$requestUri);#当前文件的脚本文件地址
defined('SERVER_HOST')?SERVER_HOST:define('SERVER_HOST',$http_type.$httpHost.'/');#域名地址
defined('SERVER_NAME')?SERVER_NAME:define('SERVER_NAME',$http_type.$httpHost);#不带 / 的域名
defined('APP_PATH')?APP_PATH:define('APP_PATH',str_replace('\\','/',dirname(dirname(dirname(__FILE__))).'/'.APP_NAME.'/'));
defined('PROJECT_PATH')?PROJECT_PATH:define('PROJECT_PATH',dirname(APP_PATH));#得到工程路径
if(PROJECT_PATH != DOC_ROOT){
$arr=explode('/',PROJECT_PATH);#分解工程
defined('PROJECT_NAME')?PROJECT_NAME:define('PROJECT_NAME',end($arr));#得到工程名并设置全局常量
}else{
 defined('PROJECT_NAME')?PROJECT_NAME:define('PROJECT_NAME',APP_NAME);#得到工程名并设置全局常量
}
defined('WEB_STATIC')?WEB_STATIC:define('WEB_STATIC',PROJECT_PATH.'/'.APP_NAME.'/web/');#静态渲染层地址	
defined('ROOT_PATH')?ROOT_PATH:define('ROOT_PATH',str_ireplace('\\','/',dirname(dirname(__FILE__))).'/');#得到当前的系统跟目录地址
defined('APP_HOST')?APP_HOST:define('APP_HOST',$httpHost.'/');
unset($http_type,$is_version,$httpHost,$requestUri,$project_work,$project_name,$arr,$environment);#手动销毁相应的变量
include_once ROOT_PATH.'common/define.php';#加载你的应用程序常量
######################################## php.ini config ###############################################
#程序对服务器的安全配置
ini_set('safe_mode','On');#打开php安全模式
ini_set('expose_php','Off');#对外隐藏php版本信息
ini_set('log_errors','On');#打开错误日志功能
ini_set('error_log',APP_PATH.'data/error_log/general_errors.log');#记录错误日志文件
ini_set('register_globals','Off');#关闭<strong>全局变量</strong>注册
ini_set('memory_limit','512M');#设置运行内存
ini_set('session.cache_expire',  180);
ini_set('session.use_trans_sid', 0);
ini_set('session.use_cookies',   1);
ini_set('session.auto_start',    0);
ini_set('session.gc_maxlifetime', 'time_in_seconds');
ini_set('session.name','zhphpsession');
ini_set('session.gc_probability',0);
ini_set('session.cookie_path',SESSION_PATH);
ini_set('session.cookie_domain',SESSION_DOMAIN);
ini_set('session.cookie_lifetime', '1800');
ini_set('session.save_path',SESSION_PATH);
include_once ROOT_PATH.'engine/loader.class.php'; #加载loader类
loader::init();
engine::loadCommon('common');#加载系统工具函数文件
config::loadConfig();#加载配置
set_error_handler('error');#自定义错误函数
################################## 开发环境  调试 ################################################################
$envir
switch($environment){
    case 1: defined('HTTP_URL')?HTTP_URL:define('HTTP_URL',SERVER_HOST.PROJECT_NAME.'/'); break;#设置全局常量
    case 2: defined('HTTP_URL')?HTTP_URL:define('HTTP_URL',SERVER_HOST); break;
    case 3: echo '等待测试'; break;
}
#设置错误显示级别
if(APP_DEBUG){
    ini_set('display_errors', true);
    error_reporting(E_ALL);
    browserDebug();#加载浏览器调试工具,方便在开发的时候,在浏览器调试,目前支持Firefox,Chrome
}else{
    ini_set('display_errors', false);
    error_reporting(0);
}
$GLOBALS['router']=engine::load('router');#路由引擎并实例化结果
############################## 预防<strong>sql注入</strong>与程序安全预防 start ################################
checkSafeInput();
if (!get_magic_quotes_gpc()) {
      $_GET       = addslashes_deep($_GET);
      $_POST      = addslashes_deep($_POST);
      $_COOKIE    = addslashes_deep($_COOKIE);
      $_REQUEST   = addslashes_deep($_REQUEST);
}
Nach dem Login kopieren

以上就介绍了zhphp framework 三 框架工作流程,包括了version_compare,全局变量,sql注入方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage