ѡ̳

 找回密码
 ע
搜索
查看: 156|回复: 0
打印 上一主题 下一主题

phpcms的参数处理类param.class.php

[复制链接]

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
跳转到指定楼层
¥
发表于 2017-11-12 19:25:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
源码
  1. <?php
  2. /**
  3. *  param.class.php        参数处理类
  4. *
  5. * @copyright                        (C) 2005-2012 PHPCMS
  6. * @license                                http://www.phpcms.cn/license/
  7. * @lastmodify                        2012-9-17
  8. */
  9. class param {

  10.         //路由配置
  11.         private $route_config = '';
  12.        
  13.         public function __construct() {
  14.                 if(!get_magic_quotes_gpc()) {
  15.                         $_POST = new_addslashes($_POST);
  16.                         $_GET = new_addslashes($_GET);
  17.                         $_REQUEST = new_addslashes($_REQUEST);
  18.                         $_COOKIE = new_addslashes($_COOKIE);
  19.                 }

  20.                 $this->route_config = pc_base::load_config('route', SITE_URL) ? pc_base::load_config('route', SITE_URL) : pc_base::load_config('route', 'default');

  21.                 if(isset($this->route_config['data']['POST']) && is_array($this->route_config['data']['POST'])) {
  22.                         foreach($this->route_config['data']['POST'] as $_key => $_value) {
  23.                                 if(!isset($_POST[$_key])) $_POST[$_key] = $_value;
  24.                         }
  25.                 }
  26.                 if(isset($this->route_config['data']['GET']) && is_array($this->route_config['data']['GET'])) {
  27.                         foreach($this->route_config['data']['GET'] as $_key => $_value) {
  28.                                 if(!isset($_GET[$_key])) $_GET[$_key] = $_value;
  29.                         }
  30.                 }
  31.                 if(isset($_GET['page'])) {
  32.                         $_GET['page'] = max(intval($_GET['page']),1);
  33.                         $_GET['page'] = min($_GET['page'],1000000000);
  34.                 }
  35.                 return true;
  36.         }

  37.         /**
  38.          * 获取模型
  39.          */
  40.         public function route_m() {
  41.                 $m = isset($_GET['m']) && !empty($_GET['m']) ? $_GET['m'] : (isset($_POST['m']) && !empty($_POST['m']) ? $_POST['m'] : '');
  42.                 $m = $this->safe_deal($m);
  43.                 if (empty($m)) {
  44.                         return $this->route_config['m'];
  45.                 } else {
  46.                         if(is_string($m)) return $m;
  47.                 }
  48.         }

  49.         /**
  50.          * 获取控制器
  51.          */
  52.         public function route_c() {
  53.                 $c = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : (isset($_POST['c']) && !empty($_POST['c']) ? $_POST['c'] : '');
  54.                 $c = $this->safe_deal($c);
  55.                 if (empty($c)) {
  56.                         return $this->route_config['c'];
  57.                 } else {
  58.                         if(is_string($c)) return $c;
  59.                 }
  60.         }

  61.         /**
  62.          * 获取事件
  63.          */
  64.         public function route_a() {
  65.                 $a = isset($_GET['a']) && !empty($_GET['a']) ? $_GET['a'] : (isset($_POST['a']) && !empty($_POST['a']) ? $_POST['a'] : '');
  66.                 $a = $this->safe_deal($a);
  67.                 if (empty($a)) {
  68.                         return $this->route_config['a'];
  69.                 } else {
  70.                         if(is_string($a)) return $a;
  71.                 }
  72.         }

  73.         /**
  74.          * 设置 cookie
  75.          * @param string $var     变量名
  76.          * @param string $value   变量值
  77.          * @param int $time    过期时间
  78.          */
  79.         public static function set_cookie($var, $value = '', $time = 0) {
  80.                 $time = $time > 0 ? $time : ($value == '' ? SYS_TIME - 3600 : 0);
  81.                 $s = $_SERVER['SERVER_PORT'] == '443' ? 1 : 0;
  82.                 $httponly = $var=='userid'||$var=='auth'?true:false;
  83.                 $var = pc_base::load_config('system','cookie_pre').$var;
  84.                 $_COOKIE[$var] = $value;
  85.                 if (is_array($value)) {
  86.                         foreach($value as $k=>$v) {
  87.                                 setcookie($var.'['.$k.']', sys_auth($v, 'ENCODE', md5(PC_PATH.'cookie'.$var).pc_base::load_config('system','auth_key')), $time, pc_base::load_config('system','cookie_path'), pc_base::load_config('system','cookie_domain'), $s, $httponly);
  88.                         }
  89.                 } else {
  90.                         setcookie($var, sys_auth($value, 'ENCODE', md5(PC_PATH.'cookie'.$var).pc_base::load_config('system','auth_key')), $time, pc_base::load_config('system','cookie_path'), pc_base::load_config('system','cookie_domain'), $s, $httponly);
  91.                 }
  92.         }

  93.         /**
  94.          * 获取通过 set_cookie 设置的 cookie 变量
  95.          * @param string $var 变量名
  96.          * @param string $default 默认值
  97.          * @return mixed 成功则返回cookie 值,否则返回 false
  98.          */
  99.         public static function get_cookie($var, $default = '') {
  100.                 $var = pc_base::load_config('system','cookie_pre').$var;
  101.                 $value = isset($_COOKIE[$var]) ? sys_auth($_COOKIE[$var], 'DECODE', md5(PC_PATH.'cookie'.$var).pc_base::load_config('system','auth_key')) : $default;
  102.                 if(in_array($var,array('_userid','userid','siteid','_groupid','_roleid'))) {
  103.                         $value = intval($value);
  104.                 } elseif(in_array($var,array('_username','username','_nickname','admin_username','sys_lang'))) { //  site_model auth
  105.                         $value = safe_replace($value);
  106.                 }
  107.                 return $value;
  108.         }

  109.         /**
  110.          * 安全处理函数
  111.          * 处理m,a,c
  112.          */
  113.         private function safe_deal($str) {
  114.                 return str_replace(array('/', '.'), '', $str);
  115.         }

  116. }
  117. ?>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | ע

本版积分规则

QQ|Archiver|ֻ|С|ѡ̳

GMT+8, 2026-5-2 05:54 , Processed in 0.081645 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表
0.0957s