[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_sessions.php

Zen Cart 源代码 init_sessions.php




下载文件

文件名: init_sessions.php
文件类型: PHP文件
文件大小: 5.11 KiB
MD5: e890124a50a37e3ba284befb85b0de16

init_sessions.php - 关闭高亮
  1. <?php
  2. /**
  3.  * session handling
  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-2010 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 $Id: init_sessions.php 18031 2010-10-23 21:30:12Z wilt $
  11.  */
  12. if (!defined('IS_ADMIN_FLAG')) {
  13.   die('Illegal Access');
  14. }
  15. /**
  16.  * sanity check in case zenid has been incorrectly supplied as an htmlencoded param name
  17.  */
  18. if (!isset($_GET['zenid']) && isset($_GET['amp;zenid'])) {
  19.   $_GET['zenid'] = $_GET['amp;zenid'];
  20.   unset($_GET['amp;zenid']);
  21. } else if (isset($_GET['amp;zenid'])) {
  22.   unset($_GET['amp;zenid']);
  23. }
  24.  
  25. /**
  26.  * require the session handling functions
  27.  */
  28. require(DIR_WS_FUNCTIONS . 'sessions.php');
  29. /**
  30.  * set the session name and save path
  31.  */
  32. zen_session_name('zenid');
  33. zen_session_save_path(SESSION_WRITE_DIRECTORY);
  34. /**
  35.  * set the session cookie parameters
  36.  */
  37. $path = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
  38. if (defined('SESSION_USE_ROOT_COOKIE_PATH') && SESSION_USE_ROOT_COOKIE_PATH  == 'True') $path = '/';
  39. $path = (defined('CUSTOM_COOKIE_PATH')) ? CUSTOM_COOKIE_PATH : $path;
  40. $domainPrefix = (!defined('SESSION_ADD_PERIOD_PREFIX') || SESSION_ADD_PERIOD_PREFIX == 'True') ? '.' : '';
  41.  
  42. if (PHP_VERSION >= '5.2.0') {
  43.   session_set_cookie_params(0, $path, (zen_not_null($cookieDomain) ? $domainPrefix . $cookieDomain : ''), FALSE, TRUE);
  44. } else {
  45.   session_set_cookie_params(0, $path, (zen_not_null($cookieDomain) ? $domainPrefix . $cookieDomain : ''));
  46. }
  47. /**
  48.  * set the session ID if it exists
  49.  */
  50. if (isset($_POST[zen_session_name()])) {
  51.   zen_session_id($_POST[zen_session_name()]);
  52. } elseif ( ($request_type == 'SSL') && isset($_GET[zen_session_name()]) ) {
  53.   zen_session_id($_GET[zen_session_name()]);
  54. }
  55. /**
  56.  * need to tidy up $_SERVER['REMOTE_ADDR'] here beofre we use it any where else
  57.  * one problem we don't address here is if $_SERVER['REMOTE_ADDRESS'] is not set to anything at all
  58.  */
  59. $ipAddressArray = explode(',', $_SERVER['REMOTE_ADDR']);
  60. $ipAddress = (sizeof($ipAddressArray) > 0) ? $ipAddressArray[0] : '';
  61. $_SERVER['REMOTE_ADDR'] = $ipAddress;
  62. /**
  63.  * start the session
  64.  */
  65. $session_started = false;
  66. if (SESSION_FORCE_COOKIE_USE == 'True') {
  67.   zen_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, '/', (zen_not_null($current_domain) ? $current_domain : ''));
  68.  
  69.   if (isset($_COOKIE['cookie_test'])) {
  70.     zen_session_start();
  71.     $session_started = true;
  72.   }
  73. } elseif (SESSION_BLOCK_SPIDERS == 'True') {
  74.   $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  75.   $spider_flag = false;
  76.   if (zen_not_null($user_agent)) {
  77.     $spiders = file(DIR_WS_INCLUDES . 'spiders.txt');
  78.     for ($i=0, $n=sizeof($spiders); $i<$n; $i++) {
  79.       if (zen_not_null($spiders[$i]) && substr($spiders[$i], 0, 4) != '$Id:') {
  80.         if (is_integer(strpos($user_agent, trim($spiders[$i])))) {
  81.           $spider_flag = true;
  82.           break;
  83.         }
  84.       }
  85.     }
  86.   }
  87.   if ($spider_flag == false) {
  88.     zen_session_start();
  89.     $session_started = true;
  90.   } else {
  91.     if (isset($_GET['zenid']) && $_GET['zenid'] != '') {
  92.       $tmp = (isset($_GET['main_page']) && $_GET['main_page'] != '') ? $_GET['main_page'] : FILENAME_DEFAULT;
  93.       @header("HTTP/1.1 301 Moved Permanently");
  94.       @zen_redirect(@zen_href_link($tmp, @zen_get_all_get_params(array('zenid')), $request_type, FALSE));
  95.       unset($tmp);
  96.       die();
  97.     }
  98.   }
  99. } else {
  100.   zen_session_start();
  101.   $session_started = true;
  102. }
  103. unset($spiders);
  104. /**
  105.  * set host_address once per session to reduce load on server
  106.  */
  107. if (!isset($_SESSION['customers_host_address'])) {
  108.   if (SESSION_IP_TO_HOST_ADDRESS == 'true') {
  109.     $_SESSION['customers_host_address']= @gethostbyaddr($_SERVER['REMOTE_ADDR']);
  110.   } else {
  111.     $_SESSION['customers_host_address'] = OFFICE_IP_TO_HOST_ADDRESS;
  112.   }
  113. }
  114. /**
  115.  * verify the ssl_session_id if the feature is enabled
  116.  */
  117. if ( ($request_type == 'SSL') && (SESSION_CHECK_SSL_SESSION_ID == 'True') && (ENABLE_SSL == 'true') && ($session_started == true) ) {
  118.   $ssl_session_id = $_SERVER['SSL_SESSION_ID'];
  119.   if (!$_SESSION['SSL_SESSION_ID']) {
  120.     $_SESSION['SSL_SESSION_ID'] = $ssl_session_id;
  121.   }
  122.   if ($_SESSION['SSL_SESSION_ID'] != $ssl_session_id) {
  123.     zen_session_destroy();
  124.     zen_redirect(zen_href_link(FILENAME_SSL_CHECK));
  125.   }
  126. }
  127. /**
  128.  * verify the browser user agent if the feature is enabled
  129.  */
  130. if (SESSION_CHECK_USER_AGENT == 'True') {
  131.   $http_user_agent = $_SERVER['HTTP_USER_AGENT'];
  132.   if (!$_SESSION['SESSION_USER_AGENT']) {
  133.     $_SESSION['SESSION_USER_AGENT'] = $http_user_agent;
  134.   }
  135.   if ($_SESSION['SESSION_USER_AGENT'] != $http_user_agent) {
  136.     zen_session_destroy();
  137.     zen_redirect(zen_href_link(FILENAME_LOGIN));
  138.   }
  139. }
  140. /**
  141.  * verify the IP address if the feature is enabled
  142.  */
  143. if (SESSION_CHECK_IP_ADDRESS == 'True') {
  144.   $ip_address = zen_get_ip_address();
  145.   if (!$_SESSION['SESSION_IP_ADDRESS']) {
  146.     $_SESSION['SESSION_IP_ADDRESS'] = $ip_address;
  147.   }
  148.   if ($_SESSION['SESSION_IP_ADDRESS'] != $ip_address) {
  149.     zen_session_destroy();
  150.     zen_redirect(zen_href_link(FILENAME_LOGIN));
  151.   }
  152. }
  153.