1

ユーザーが次のページに移動したときに検索クエリを取得できるように、flashdata を使用して検索クエリを保存しています。

これは、フラッシュデータを保存する方法です

$this->session->set_flashdata('searchQuery', $queryStr);

これは、フラッシュデータを取得する方法です。

$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]   
4

1 に答える 1

3

問題は、おそらくあなたの最後のものによって引き起こされRewriteCondます.htaccess

#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

上記は、アプリケーションの index.php にルーティングしてはならないリクエストを一覧表示するために使用されます。

発生する可能性があるのは、アプリケーションにルーティングしたくない icon/css/image/etc の要求がサイトに含まれていることです。このリクエストはアプリケーションを通過するため、flashdata (次のリクエストでのみ利用可能) をインターセプトしています。つまり、ページの実際のリクエストでは利用できなくなります。

他のケースもありますが、この例は多くfavicon.icoの場合 です。で指定されていなくても、Chrome はファビコンを要求すると思います<head>

favicon.ico除外されたリクエストのリストに を追加することで、これを解決できます。

RewriteCond $1 !^(favicon\.ico|index\.php|images|robots\.txt|css)

これは favicon.ico が原因ではなく、まったく別のリクエストが原因である可能性があります。これを突き止める最良の方法は、すべてのリクエストをファイルに記録し、コードのその時点で何が起こっているかを確認することです。

于 2013-10-30T01:57:57.193 に答える