[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 init_sanitize.php

Zen Cart 源代码 init_sanitize.php




下载文件

文件名: init_sanitize.php
文件类型: PHP文件
文件大小: 6.09 KiB
MD5: fda27fc84ad77829082efead10a0527b

init_sanitize.php - 关闭高亮
  1. <?php
  2. /**
  3.  * sanitize the GET parameters
  4.  * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
  5.  *
  6.  * @package initSystem
  7.  * @copyright Copyright 2003-2013 Zen Cart Development Team
  8.  * @copyright Portions Copyright 2003 osCommerce
  9.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  10.  * @version GIT: $Id: Author: Ian Wilson  Thu Nov 7 15:58:09 2013 +0000 Modified in v1.5.2 $
  11.  * @todo move the array process to security class
  12.  */
  13.  
  14.   if (!defined('IS_ADMIN_FLAG')) {
  15.     die('Illegal Access');
  16.   }
  17.   $csrfBlackListLocal = array();
  18.   $csrfBlackList = (isset($csrfBlackListCustom)) ? array_merge($csrfBlackListLocal, $csrfBlackListCustom) : $csrfBlackListLocal;
  19.   if (! isset ( $_SESSION ['securityToken'] ))
  20.   {
  21.     $_SESSION ['securityToken'] = md5 ( uniqid ( rand (), true ) );
  22.   }
  23.   if ((isset ( $_GET ['action'] ) || isset($_POST['action']) ) && $_SERVER['REQUEST_METHOD'] == 'POST')
  24.   {
  25.     $mainPage = isset($_GET['main_page']) ? $_GET['main_page'] : FILENAME_DEFAULT;
  26.     if (!in_array($mainPage, $csrfBlackList))
  27.     {
  28.       if ((! isset ( $_SESSION ['securityToken'] ) || ! isset ( $_POST ['securityToken'] )) || ($_SESSION ['securityToken'] !== $_POST ['securityToken']))
  29.       {
  30.         zen_redirect ( zen_href_link ( FILENAME_TIME_OUT, '', $request_type ) );
  31.       }
  32.     }
  33.   }
  34.   if (isset($_GET['typefilter'])) $_GET['typefilter'] = preg_replace('/[^0-9a-zA-Z_-]/', '', $_GET['typefilter']);
  35.   if (isset($_GET['products_id'])) $_GET['products_id'] = preg_replace('/[^0-9a-f:]/', '', $_GET['products_id']);
  36.   if (isset($_GET['manufacturers_id'])) $_GET['manufacturers_id'] = preg_replace('/[^0-9]/', '', $_GET['manufacturers_id']);
  37.   if (isset($_GET['categories_id'])) $_GET['categories_id'] = preg_replace('/[^0-9]/', '', $_GET['categories_id']);
  38.   if (isset($_GET['cPath'])) $_GET['cPath'] = preg_replace('/[^0-9_]/', '', $_GET['cPath']);
  39.   if (isset($_GET['main_page'])) $_GET['main_page'] = preg_replace('/[^0-9a-zA-Z_]/', '', $_GET['main_page']);
  40.   if (isset($_GET['sort'])) $_GET['sort'] = preg_replace('/[^0-9a-zA-Z]/', '', $_GET['sort']);
  41.   $saniGroup1 = array('action', 'addr', 'alpha_filter_id', 'alpha_filter', 'authcapt', 'chapter', 'cID', 'currency', 'debug', 'delete', 'dfrom', 'disp_order', 'dto', 'edit', 'faq_item', 'filter_id', 'goback', 'goto', 'gv_no', 'id', 'inc_subcat', 'language', 'markflow', 'music_genre_id', 'nocache', 'notify', 'number_of_uploads', 'order_id', 'order', 'override', 'page', 'pfrom', 'pid', 'pID', 'pos', 'product_id', 'products_image_large_additional', 'products_tax_class_id', 'pto', 'record_company_id', 'referer', 'reviews_id', 'search_in_description', 'set_session_login', 'token', 'tx', 'type', 'zenid');
  42.   foreach ($saniGroup1 as $key)
  43.   {
  44.     if (isset($_GET[$key]))
  45.     {
  46.       $_GET[$key] = preg_replace('/[^\/0-9a-zA-Z_:@.-]/', '', $_GET[$key]);
  47.     }
  48.   }
  49.  
  50. /**
  51.  * process all $_GET terms
  52.  */
  53.   $strictReplace = '[<>\']';
  54.  $unStrictReplace = '[<>]';
  55.  if (isset($_GET) && count($_GET) > 0) {
  56.    foreach($_GET as $key=>$value){
  57.      if(is_array($value)){
  58.        foreach($value as $key2 => $val2){
  59.          if ($key2 == 'keyword') {
  60.            $_GET[$key][$key2] = preg_replace('/'.$unStrictReplace.'/', '', $val2);
  61.          } else {
  62.            $_GET[$key][$key2] = preg_replace('/'.$strictReplace.'/', '', $val2);
  63.          }
  64.          unset($GLOBALS[$key]);
  65.        }
  66.      } else {
  67.        if ($key == 'keyword') {
  68.          $_GET[$key] = preg_replace('/'.$unStrictReplace.'/', '', $value);
  69.        } else {
  70.          $_GET[$key] = preg_replace('/'.$strictReplace.'/', '', $value);
  71.        }
  72.        unset($GLOBALS[$key]);
  73.      }
  74.    }
  75.  }
  76. /**
  77. * process all $_POST terms
  78. * @todo move the array process to security class
  79. */
  80.  if (isset($_POST) && count($_POST) > 0) {
  81.    foreach($_POST as $key=>$value){
  82.      if(is_array($value)){
  83.        foreach($value as $key2 => $val2){
  84.          unset($GLOBALS[$key]);
  85.        }
  86.      } else {
  87.        unset($GLOBALS[$key]);
  88.      }
  89.    }
  90.  }
  91. /**
  92. * process all $_COOKIE terms
  93. */
  94.  if (isset($_COOKIE) && count($_COOKIE) > 0) {
  95.    foreach($_COOKIE as $key=>$value){
  96.      if(is_array($value)){
  97.        foreach($value as $key2 => $val2){
  98.          unset($GLOBALS[$key]);
  99.        }
  100.      } else {
  101.        unset($GLOBALS[$key]);
  102.      }
  103.    }
  104.  }
  105. /**
  106. * process all $_SESSION terms
  107. */
  108.  if (isset($_SESSION) && count($_SESSION) > 0) {
  109.    foreach($_SESSION as $key=>$value){
  110.      if(is_array($value)){
  111.        foreach($value as $key2 => $val2){
  112.          unset($GLOBALS[$key]);
  113.        }
  114.      } else {
  115.        unset($GLOBALS[$key]);
  116.      }
  117.    }
  118.  }
  119. /**
  120. * sanitize $_SERVER vars
  121. */
  122.  $_SERVER['REMOTE_ADDR'] = preg_replace('~[^a-fA-F0-9.:%/]~', '', $_SERVER['REMOTE_ADDR']);
  123.  
  124.  
  125. /**
  126. * validate products_id for search engines and bookmarks, etc.
  127. */
  128.  if (isset($_GET['products_id']) && isset($_SESSION['check_valid']) &&  $_SESSION['check_valid'] != 'false') {
  129.    $check_valid = zen_products_id_valid($_GET['products_id']);
  130.    if (!$check_valid) {
  131.      $_GET['main_page'] = zen_get_info_page($_GET['products_id']);
  132.      /**
  133.       * do not recheck redirect
  134.       */
  135.      $_SESSION['check_valid'] = 'false';
  136.      zen_redirect(zen_href_link($_GET['main_page'], 'products_id=' . $_GET['products_id']));
  137.    }
  138.  } else {
  139.    $_SESSION['check_valid'] = 'true';
  140.  }
  141. /**
  142. * We do some checks here to ensure $_GET['main_page'] has a sane value
  143. */
  144.  if (!isset($_GET['main_page']) || !zen_not_null($_GET['main_page'])) $_GET['main_page'] = 'index';
  145.  
  146.  if (!is_dir(DIR_WS_MODULES .  'pages/' . $_GET['main_page'])) {
  147.    if (MISSING_PAGE_CHECK == 'On' || MISSING_PAGE_CHECK == 'true') {
  148.      $_GET['main_page'] = 'index';
  149.    } elseif (MISSING_PAGE_CHECK == 'Page Not Found') {
  150.      header('HTTP/1.1 404 Not Found');
  151.      $_GET['main_page'] = FILENAME_PAGE_NOT_FOUND;
  152.    }
  153.  }
  154.  $current_page = $_GET['main_page'];
  155.  $current_page_base = $current_page;
  156.  $code_page_directory = DIR_WS_MODULES . 'pages/' . $current_page_base;
  157.  $page_directory = $code_page_directory;
  158.