我正在使用flashdata存储我的搜索查询,以便在用户导航到下一页时可以检索它。Flashdata在托管在服务器上但在本地工作时无法在Chrome上工作
这是我如何保存flashdata
$this->session->set_flashdata('searchQuery', $queryStr);
这是我如何检索flashdata。
$queryStr = $this->session->flashdata('searchQuery');
Flashdata在本地工作正常,但是当我主持它在我的服务器上,它无法在Chrome(Windows)和Chrome浏览器(Android版)的工作,但在IE(Windows)中。此外,它在Chrome(iOS)上运行得非常好。我也做了一个测试用例,它只适用于IE(Windows)和Chrome(iOS)。任何人都知道什么是错的?
class Flashdata extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
}
function index()
{
if ($var = $this->session->flashdata('test'))
{
echo "Found data: $var";
}
else
{
$this->session->set_flashdata('test', 'flash data test');
echo "Set data";
}
}
}
这里是我的.htaccess文件
# Options
Options -Multiviews
Options +FollowSymLinks
#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase/
#Removes access to CodeIgniter system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
codeigniters整个会话停止工作,或只是flashdata?如果它只是flash数据,那么可能会有一个额外的请求被触发,即清除flash数据。即使Chrome浏览器不在您的HTML中,Chrome等浏览器也会尝试请求收藏图标。如果你有一个捕获所有.htaccess这个请求可以路由到你的应用程序,这将清除flashdata。 – Jeemusu
你能发布你的.htaccess吗? – Jeemusu
我已将htaccess文件添加到上述问题中。谢谢@jeemusu – Xuanhao