ecstore等产品开启缓存-后台及前台不能登录原因-setcookie+session问题

define('WITHOUT_CACHE',false)时后台前台开启缓存-不能登录原因

1、检查这个

app/b2c/lib/frontpage.php

php 复制代码
setcookie($name,$value,$expire,$this->cookie_path,null,false,false);//null-domain要改成nul2025-07-18 16:38:02否则不能登录""

2、

app/base/lib/session.php这个文件要1==1

php 复制代码
<?php

/**

* ShopEx licence

*

* @copyright Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)

* @license http://ecos.shopex.cn/ ShopEx License

*/




class base_session{



private $_sess_id;

private $_sess_key = 's';

private $_session_started = false;

private $_sess_expires = 60;

private $_cookie_expires = 0;

private $_session_destoryed = false;



function __construct()

{

if(defined('SESS_NAME') && constant('SESS_NAME')) $this->_sess_key = constant('SESS_NAME');

if(defined('SESS_CACHE_EXPIRE') && constant('SESS_CACHE_EXPIRE')) $this->_sess_expires = constant('SESS_CACHE_EXPIRE');

}//End Function



public function sess_id(){

return $this->_sess_id;

}



public function set_sess_id($sess_id){

return $this->_sess_id=$sess_id;

}



public function set_sess_expires($minute)

{

$this->_sess_expires = $minute;

}//End Function



private function _get_cache_key(){

if (1==1 || WITHOUT_CACHE===true) {

return $this->sess_id();

}else{

return 'USER_SESSION:'.$this->sess_id();

}

}



private function _get_session(){

if (1==1 || WITHOUT_CACHE===true) {

if (base_kvstore::instance('sessions')->fetch($this->_get_cache_key(), $return)){

return $return;

}else{

return array();

}

}else{

if (cacheobject::get($this->_get_cache_key(), $return)) {

return $return;

}else{

return array();

}

}

}



private function _set_session($value, $ttl){

if (1==1 || WITHOUT_CACHE===true) {

return base_kvstore::instance('sessions')->store($this->_get_cache_key(), $value, $ttl );

}else{

return cacheobject::set($this->_get_cache_key(), $value, $ttl+time());

}

}



public function set_cookie_expires($minute)

{

$this->_cookie_expires = ($minute > 0) ? $minute : 0;

if(isset($this->_sess_id)){

$cookie_path = kernel::base_url();

$cookie_path = $cookie_path ? $cookie_path : "/";

header(sprintf('Set-Cookie: %s=%s; path=%s; expires=%s; httpOnly;', $this->_sess_key, $this->_sess_id, $cookie_path, gmdate('D, d M Y H:i:s T', time()+$minute*60)), true);

}

}//End Function



public function start(){

if($this->_session_started !== true){

$cookie_path = kernel::base_url();

$cookie_path = $cookie_path ? $cookie_path : "/";

if($this->_cookie_expires > 0){

$cookie_expires = sprintf("expires=%s;", gmdate('D, d M Y H:i:s T', time()+$this->_cookie_expires*60));

}else{

$cookie_expires = '';

}

if(isset($_GET['sess_id'])){

$this->_sess_id = $_GET['sess_id'];

if($_COOKIE[$this->_sess_key] != $_GET['sess_id'])

header(sprintf('Set-Cookie: %s=%s; path=%s; %s; httpOnly; ', $this->_sess_key, $this->_sess_id, $cookie_path, $cookie_expires), true);

$_SESSION = $this->_get_session();

}elseif($_COOKIE[$this->_sess_key]){

$this->_sess_id = $_COOKIE[$this->_sess_key];

$_SESSION = $this->_get_session();

}elseif(!$this->_sess_id){

$this->_sess_id = $this->gen_session_id();

$_SESSION = array();

header(sprintf('Set-Cookie: %s=%s; path=%s; %s; httpOnly; ', $this->_sess_key, $this->_sess_id, $cookie_path, $cookie_expires), true);

}

$this->_session_started = true;

register_shutdown_function(array(&$this,'close'));

}

return true;

}



public function close($writeBack = true){

if(strlen($this->_sess_id) != 32){

return false;

}

if(!$this->_session_started){

return false;

}

$this->_session_started = false;

if(!$writeBack){

return false;

}

if($this->_session_destoryed){

return true;

}else{

try {

return $this->_set_session($_SESSION, $this->_sess_expires * 60 * 24);

}catch(Exception $e){



}

}

}



protected function gen_session_id() {

return md5(uniqid('', true).base_request::get_remote_addr().microtime(true).mt_rand(0,9999));

}



public function destory(){

if(!$this->_session_started){

return false;

}

$this->_session_started = false;

$res = $this->_set_session(array(), 1);

if($res){

$_SESSION = array();

$this->_session_destoryed = true;

$cookie_path = kernel::base_url();

$cookie_path = $cookie_path ? $cookie_path : "/";

header(sprintf('Set-Cookie: %s=%s; path=%s; httpOnly;', $this->_sess_key, $this->_sess_id, $cookie_path), true);

unset($this->_sess_id);

return true;

}else{

return false;

}

}



}
相关推荐
晚枫歌F21 小时前
Dpdk介绍
linux·服务器
李慕婉学姐21 小时前
【开题答辩过程】以《基于JAVA的校园即时配送系统的设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
java·开发语言·数据库
web小白成长日记21 小时前
企业级 Vue3 + Element Plus 主题定制架构:从“能用”到“好用”的进阶之路
前端·架构
APIshop21 小时前
Python 爬虫获取 item_get_web —— 淘宝商品 SKU、详情图、券后价全流程解析
前端·爬虫·python
风送雨21 小时前
FastMCP 2.0 服务端开发教学文档(下)
服务器·前端·网络·人工智能·python·ai
XTTX11021 小时前
Vue3+Cesium教程(36)--动态设置降雨效果
前端·javascript·vue.js
LYFlied1 天前
WebGPU与浏览器边缘智能:开启去中心化AI新纪元
前端·人工智能·大模型·去中心化·区块链
奋进的芋圆1 天前
Java 延时任务实现方案详解(适用于 Spring Boot 3)
java·spring boot·redis·rabbitmq
Setsuna_F_Seiei1 天前
2025 年度总结:人生重要阶段的一年
前端·程序员·年终总结
sxlishaobin1 天前
设计模式之桥接模式
java·设计模式·桥接模式