1

我有一个用代码点火器编写的 PHP 程序,需要你的帮助!已经尝试了3周!

我有 htaccess mod 重写以制作http://www.sampleurl.com/controllername而不是http://www.sampleurl.com/index.php/controllername

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule> 

我有一个仪表板控制器(目前用于测试会话。)

public function index()
    {
            $is_logged_in = $this->session->userdata('fb_session');

            $data = array(
                'fb_data' => $is_logged_in,
            );

            if (!isset($is_logged_in) || $is_logged_in != true){
                redirect('/error');
            }


        }

下面是假设终止当前会话并重定向到仪表板页面的功能。

$('#logoutbtn').click(function(){
         $.ajax({
            type:"POST",
            url: "/fbcontroller/killsession",
            datatype: "json",
            success: function(){
                alert("Logout");
            }
         });
    });


 public function killsession(){
           $this->session->sess_destroy();
            redirect('/dashboard');
        }

问题 1:当我从 1 个控制器中的功能重定向到另一个控制器时,重定向在此处失败。萤火虫没有定向到仪表板,而是显示 404 错误,找不到页面。并在响应中显示 /error 页面的所有 HTML 代码。这是否意味着重定向有效?如果是,为什么它不会显示在浏览器上?

问题 2:会话被破坏,但即使我刷新 (F5) 时登录页面仍然存在。

4

1 回答 1

3

对于 htaccess,我建议:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

并且知道,当您终止会话时,CI 将在您的下一个页面加载时创建一个新的 1(在您的情况下为重定向).. 会话不仅用于用户登录。

不要忘记在 app/config/config.php 设置

$config["index_page"] = '';
于 2013-10-16T09:09:32.790 回答