实时服务器上的 CI4 未反映所做的更改,它显示旧数据。不反映动态内容和其他变化
CI4 on live server not reflecting changes made, it shows old data. Dynamic contents and other changes are not reflected
我使用 CI4 创建了一个网站并且运行良好。在 WAMP 服务器上它工作正常。现在,如果更改任何内容并更新服务器,它会显示旧数据和会话有时无法正常工作。我认为浏览器正在缓存网页。有什么方法可以在 CI4 中禁用吗?是缓存问题还是会话?
“旧数据”意味着如果我更改 css 或 html 的一部分,它不会反映更改,而旧的 html 显示。动态数据也是如此。
无法登录,会话未保存登录详细信息。对于会话,我正在使用数据库。在本地服务器上一切正常,仅在实时服务器上发布。我正在使用 plesk 主机。
有人遇到过这个问题吗?
在新电脑上试用时,它工作正常。如果进行任何更新并重试,问题就会出现。
在基本控制器中发起的会话:
$this->session = \Config\Services::session();
我在控制器中使用这个进行缓存控制:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
//header("Cache-Control: public, max-age=60, s-maxage=60");
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
会话的应用程序配置:
public $sessionDriver = 'CodeIgniter\Session\Handlers\DatabaseHandler';
public $sessionCookieName = 'ci_session';
public $sessionSavePath = 'ci_sessions';
public $sessionExpiration = 7200;
//public $sessionSavePath = WRITEPATH . 'session';
public $sessionMatchIP = false;
public $sessionTimeToUpdate = 300;
public $sessionRegenerateDestroy = false;
已尝试 Empty/Cache 并重新加载。代码中没有启用缓存。
编辑:
我检查了评论中提到的浏览器,它正在缓存:
accept-ranges: bytes
cache-control: max-age=315360000
content-encoding: gzip
content-length: 9333
content-security-policy: upgrade-insecure-requests;
content-type: text/css
date: Thu, 14 Jan 2021 13:07:22 GMT
etag: "f0fc6fe8a1bdd61:0"
expires: Thu, 31 Dec 2037 23:55:55 GMT
last-modified: Wed, 18 Nov 2020 11:56:54 GMT
server: nginx
vary: Accept-Encoding
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-powered-by-plesk: PleskWin
x-sucuri-cache: HIT
x-sucuri-id: 18015
x-xss-protection: 1; mode=block
我不知道这是怎么缓存的。
基地控制器:
<?php
namespace App\Controllers;
/**
* Class BaseController
*
* BaseController provides a convenient place for loading components
* and performing functions that are needed by all your controllers.
* Extend this class in any new controllers:
* class Home extends BaseController
*
* For security be sure to declare any new methods as protected or private.
*
* @package CodeIgniter
*/
use CodeIgniter\Controller;
use Config\Services;
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
class BaseController extends Controller
{
/**
* An array of helpers to be loaded automatically upon
* class instantiation. These helpers will be available
* to all other controllers that extend BaseController.
*
* @var array
*/
protected $helpers = ['form', 'url','master'];
protected $session;
/**
* Constructor.
*/
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
$this->session = \Config\Services::session();
date_default_timezone_set('Asia/Dubai');
$this->pager = \Config\Services::pager();
}
}
这是登录函数:
public function login($type = 0)
{
$session = session();
$model = new HomeModel();
$model1 = new CartModel;
if ($this->request->getMethod() == 'post') {
if (!$this->validate([
'email' => [
'label' => 'Email',
'rules' => 'trim|required|is_not_unique[tbl_customers.email]',
'errors' => ['is_not_unique' => '{value}-Email is not registered with us']
],
'current-password' => ['label' => 'Password', 'rules' => 'trim|required']
])) {
$data['validation'] = $this->validator;
$page = 'login_page';
if (!is_file(APPPATH . '/Views/home/' . $page . '.php')) {
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page);
return view('home/login_page', $data);
} else {
$status = $model->checkLogin($this->request->getVar());
if (isset($status)) {
$session->remove('customerData');
session()->set('customerData', $status);
$cmsrDetails = session('customerData');
if (!empty(cart()->contents())) {
$cart = cart()->contents();
foreach ($cart as $key => $value) {
$is_exist = $model1->checkItems($value['rowid'], $cmsrDetails['customerID']);
if (!empty($is_exist)) {
if ($value['qty'] != 0) {
$data = [
'qty' => $value['qty']
];
$model1->update($is_exist['id'], $data);
} else {
$model1->delete($is_exist['id']);
}
} else {
$datain = [
'CMid' => $cmsrDetails['customerID'],
'rowId' => $value['rowid'],
'itemId' => $value['id'],
'qty' => $value['qty']
];
$model1->insert($datain);
}
}
}
$getCart = $model1->CartItems($cmsrDetails['customerID']);
if (!empty($getCart)) {
$model1->UpdateCart($getCart);
}
return redirect()->to('/');
} else {
$_SESSION['error'] = 'Username or Password incorrect';
$session->markAsFlashdata('error');
}
}
}
if (!empty(session('customerData'))) {
return redirect()->to('/');
}
//$data['validation'] = $this->validator;
$page = 'login_page';
if (!is_file(APPPATH . '/Views/home/' . $page . '.php')) {
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page);
echo view('home/login_page', $data);
}
我只是按照 Dont Panic 提到的方式让它工作了大约 90%,将 header() 添加到控制器并将 $response->noCache();
添加到基本控制器。
现在登录和其他功能工作正常。
感谢大家的帮助
我使用 CI4 创建了一个网站并且运行良好。在 WAMP 服务器上它工作正常。现在,如果更改任何内容并更新服务器,它会显示旧数据和会话有时无法正常工作。我认为浏览器正在缓存网页。有什么方法可以在 CI4 中禁用吗?是缓存问题还是会话?
“旧数据”意味着如果我更改 css 或 html 的一部分,它不会反映更改,而旧的 html 显示。动态数据也是如此。
无法登录,会话未保存登录详细信息。对于会话,我正在使用数据库。在本地服务器上一切正常,仅在实时服务器上发布。我正在使用 plesk 主机。
有人遇到过这个问题吗?
在新电脑上试用时,它工作正常。如果进行任何更新并重试,问题就会出现。
在基本控制器中发起的会话:
$this->session = \Config\Services::session();
我在控制器中使用这个进行缓存控制:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
//header("Cache-Control: public, max-age=60, s-maxage=60");
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
会话的应用程序配置:
public $sessionDriver = 'CodeIgniter\Session\Handlers\DatabaseHandler';
public $sessionCookieName = 'ci_session';
public $sessionSavePath = 'ci_sessions';
public $sessionExpiration = 7200;
//public $sessionSavePath = WRITEPATH . 'session';
public $sessionMatchIP = false;
public $sessionTimeToUpdate = 300;
public $sessionRegenerateDestroy = false;
已尝试 Empty/Cache 并重新加载。代码中没有启用缓存。
编辑: 我检查了评论中提到的浏览器,它正在缓存:
accept-ranges: bytes
cache-control: max-age=315360000
content-encoding: gzip
content-length: 9333
content-security-policy: upgrade-insecure-requests;
content-type: text/css
date: Thu, 14 Jan 2021 13:07:22 GMT
etag: "f0fc6fe8a1bdd61:0"
expires: Thu, 31 Dec 2037 23:55:55 GMT
last-modified: Wed, 18 Nov 2020 11:56:54 GMT
server: nginx
vary: Accept-Encoding
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-powered-by-plesk: PleskWin
x-sucuri-cache: HIT
x-sucuri-id: 18015
x-xss-protection: 1; mode=block
我不知道这是怎么缓存的。
基地控制器:
<?php
namespace App\Controllers;
/**
* Class BaseController
*
* BaseController provides a convenient place for loading components
* and performing functions that are needed by all your controllers.
* Extend this class in any new controllers:
* class Home extends BaseController
*
* For security be sure to declare any new methods as protected or private.
*
* @package CodeIgniter
*/
use CodeIgniter\Controller;
use Config\Services;
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
class BaseController extends Controller
{
/**
* An array of helpers to be loaded automatically upon
* class instantiation. These helpers will be available
* to all other controllers that extend BaseController.
*
* @var array
*/
protected $helpers = ['form', 'url','master'];
protected $session;
/**
* Constructor.
*/
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
$this->session = \Config\Services::session();
date_default_timezone_set('Asia/Dubai');
$this->pager = \Config\Services::pager();
}
}
这是登录函数:
public function login($type = 0)
{
$session = session();
$model = new HomeModel();
$model1 = new CartModel;
if ($this->request->getMethod() == 'post') {
if (!$this->validate([
'email' => [
'label' => 'Email',
'rules' => 'trim|required|is_not_unique[tbl_customers.email]',
'errors' => ['is_not_unique' => '{value}-Email is not registered with us']
],
'current-password' => ['label' => 'Password', 'rules' => 'trim|required']
])) {
$data['validation'] = $this->validator;
$page = 'login_page';
if (!is_file(APPPATH . '/Views/home/' . $page . '.php')) {
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page);
return view('home/login_page', $data);
} else {
$status = $model->checkLogin($this->request->getVar());
if (isset($status)) {
$session->remove('customerData');
session()->set('customerData', $status);
$cmsrDetails = session('customerData');
if (!empty(cart()->contents())) {
$cart = cart()->contents();
foreach ($cart as $key => $value) {
$is_exist = $model1->checkItems($value['rowid'], $cmsrDetails['customerID']);
if (!empty($is_exist)) {
if ($value['qty'] != 0) {
$data = [
'qty' => $value['qty']
];
$model1->update($is_exist['id'], $data);
} else {
$model1->delete($is_exist['id']);
}
} else {
$datain = [
'CMid' => $cmsrDetails['customerID'],
'rowId' => $value['rowid'],
'itemId' => $value['id'],
'qty' => $value['qty']
];
$model1->insert($datain);
}
}
}
$getCart = $model1->CartItems($cmsrDetails['customerID']);
if (!empty($getCart)) {
$model1->UpdateCart($getCart);
}
return redirect()->to('/');
} else {
$_SESSION['error'] = 'Username or Password incorrect';
$session->markAsFlashdata('error');
}
}
}
if (!empty(session('customerData'))) {
return redirect()->to('/');
}
//$data['validation'] = $this->validator;
$page = 'login_page';
if (!is_file(APPPATH . '/Views/home/' . $page . '.php')) {
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page);
echo view('home/login_page', $data);
}
我只是按照 Dont Panic 提到的方式让它工作了大约 90%,将 header() 添加到控制器并将 $response->noCache();
添加到基本控制器。
现在登录和其他功能工作正常。 感谢大家的帮助