sdisTablet()) { $device = '.tab'; } elseif($device_type->isMobile()) { $device = '.mob'; } } if(PAGE_TIMING) { include('timer.class.php'); $timer = new timer(true); } if(OCPC_SESH_SWITCH) { if(!empty($_POST['pcsesh-pass']) && !empty($_POST['session_id']) && !empty($_POST['token']) && !empty($_POST['pcsesh-cookie'])) { $key = $_POST['pcsesh-cookie']; setcookie('default', $key, ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly')); ini_set('session.use_only_cookies', 'Off'); ini_set('session.use_cookies', 'On'); ini_set('session.use_trans_sid', 'Off'); ini_set('session.cookie_httponly', 'On'); session_id($_POST['session_id']); session_set_cookie_params(0, '/'); session_start(); #echo '
' . print_r($_COOKIE, true) . ''; #die(); if(empty($_SESSION[$key]['token']) || $_POST['token'] != $_SESSION[$key]['token']) { session_destroy(); die('HACK ATTEMPT DETECTED!'); } header('Location: ' . $_POST['pcsesh_url']); die(); } } require_once(DIR_SYSTEM . 'library/session.php'); require_once(DIR_SYSTEM . 'library/session/native.php'); $f = new Session(); $f->start(); $session_data = $f->data; /* if (!session_id()) { ini_set('session.use_only_cookies', 'Off'); ini_set('session.use_cookies', 'On'); ini_set('session.use_trans_sid', 'Off'); ini_set('session.cookie_httponly', 'On'); if(OCPC_SESH_SWITCH) { if(!empty($_POST['pcsesh-pass']) && !empty($_POST['session_id']) && !empty($_POST['token'])) { session_id($_POST['session_id']); session_set_cookie_params(0, '/'); session_start(); if(empty($session_data['token']) || $_POST['token'] != $session_data['token']) { session_destroy(); die('HACK ATTEMPT DETECTED!'); } header('Location: ' . $_POST['pcsesh_url']); die(); } } if (isset($_COOKIE[session_name()]) && !preg_match('/^[a-zA-Z0-9,\-]{22,40}$/', $_COOKIE[session_name()])) { exit(); } if ($session_id) { session_id($session_id); } session_set_cookie_params(0, '/'); session_start(); } */ if(!empty($session_data['user_id'])) { // Set user id and token values if available for reference $page_cache_user_id = $session_data['user_id']; $page_cache_user_token = $session_data['token']; } header('X-JG-Page-Cache: ' . PAGE_CACHE_VERSION); // Check request is a GET call if(!empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' && (OCPC_CACHE_HTTPS || (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off'))) { $skipped_routes_file = realpath(dirname(__FILE__)) . '/skipped_routes.txt'; // Check route skip file exists if(file_exists($skipped_routes_file)) { $routes = @file_get_contents($skipped_routes_file); if(is_string($routes) && !empty($routes)) { $caching_restricted_routes = preg_split('~[\r\n]+~', $routes); } } // Check this is a guest with no items in cart if(empty($session_data['customer_id']) && empty($session_data['affiliate_id']) && empty($_GET['affiliate']) && empty($session_data['jg_product_count']) && empty($session_data['vouchers'])) { // Get domain name for multisite $domain = (empty($_SERVER['HTTP_HOST']) || !is_string($_SERVER['HTTP_HOST'])) ? 'unknown' : $_SERVER['HTTP_HOST']; $domain = preg_replace('/^www\./i', '', $domain); // Multi lingual support $language = (empty($session_data['language']) || !is_string($session_data['language'])) ? OCPC_DEF_LANG : $session_data['language']; // Multi currency support $currency = (empty($session_data['currency']) || !is_string($session_data['currency'])) ? OCPC_DEF_CUR : $session_data['currency']; // Load $_GET variables, sort them, convert to http query and SHA1 the string $get = $_GET; ksort($get); $key = strtolower("$domain/$language/$currency/") . http_build_query($get); $requestKey = sha1($key) . $device; header('X-JG-Page-Cache-Key: ' . $requestKey); $dirPath = DIR_PAGE_CACHE; if(OCPC_SUB_FOLDERS) { $dirPath .= substr($requestKey, 0, 2) . '/'; if(!is_dir($dirPath)) { $old = umask(0); mkdir($dirPath, OCPC_CACHE_MODE); umask($old); } } if(PAGE_ZLIB) $requestKey .= '.gz'; // Cache filename $pageCacheFile = $dirPath . 'cache.' . $requestKey; // If the file exists, output the cache file if(file_exists($pageCacheFile)) { $fileAge = floor((time() - filemtime($pageCacheFile)) / 3600); if(AUTO_EXPIRE_TIME == 0 || $fileAge < AUTO_EXPIRE_TIME) { if(PAGE_ZLIB) { $data = utf8_decode(gzencode_workaround(file_get_contents($pageCacheFile))); } else { $data = utf8_decode(file_get_contents($pageCacheFile)); } if($timer) { $data .= ' '; } if(!OCPC_USER_TIMES && empty($session_data['user_id'])) { $data = preg_replace('~~', '', $data); } if(ADMIN_SHOW_BAR && $page_cache_user_id) { $data = addBar($data, $requestKey, $page_cache_user_token); } if(!headers_sent()) header('Content-Type: text/html; charset=UTF-8'); if(GZIP_OUTPUT) { die(caching_gzip_content($data)); } else { die($data); } } } } } } function gzencode_workaround($gzData) { if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) { $i = 10; $flg = ord( substr($gzData, 3, 1) ); if ( $flg > 0 ) { if ( $flg & 4 ) { list($xlen) = unpack('v', substr($gzData, $i, 2) ); $i = $i + 2 + $xlen; } if ( $flg & 8 ) $i = strpos($gzData, "\0", $i) + 1; if ( $flg & 16 ) $i = strpos($gzData, "\0", $i) + 1; if ( $flg & 2 ) $i = $i + 2; } return @gzinflate( substr($gzData, $i, -8) ); } else { return false; } } function caching_gzip_content($data) { if(!GZIP_OUTPUT) return $data; if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)) { $encoding = 'gzip'; } if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false)) { $encoding = 'x-gzip'; } if (!isset($encoding)) { return $data; } if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) { return $data; } if (headers_sent()) { return $data; } if (connection_status()) { return $data; } header('Content-Encoding: ' . $encoding); return gzencode($data, (int)GZIP_COMPRESSION); } function addBar($content, $requestKey, $page_cache_user_token) { $requestKey = basename($requestKey, '.gz'); if(!empty($page_cache_user_token)) { $position = ADMIN_BAR_TOP ? 'top' : 'bottom'; $sub = OCPC_SUB_FOLDERS ? 1 : 0; $bar = <<
Without Caching: {without} With Caching: {with}