会话销毁并定向后,Codeigniter无法刷新页面 [英] Codeigniter cannot refresh page after session destroy and direct

查看:110
本文介绍了会话销毁并定向后,Codeigniter无法刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a PHP program written on code igniter that needs your help! Have been trying for 3 weeks!

我将htaccess mod重写为 http:// www.sampleurl.com/controllername ,而不是 http://www.sampleurl.com/ index.php / controllername

I have the htaccess mod rewrite to make http://www.sampleurl.com/controllername instead of 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> 

我有一个Dashboard控制器(当前用于测试会话)。

I have a controller for Dashboard (currently used for testing the session.)

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:当我从一个控制器中的函数重定向到另一个控制器时,重定向在这里失败。 Firebug不会显示至仪表板,而是显示404错误,找不到页面。并在响应中显示/ error页面的所有HTML代码。这是否意味着重定向有效?如果是,为什么它不显示在浏览器上?

Problem 1: as I redirect from function in 1 controller to another, the redirection fails here. Instead of directing to dashboard, the firebug displays 404 error, page not found. And in the response, it displays all the HTML code of /error page. Does it mean that the redirection works? If yes, why wouldn't it display on browser?

问题2:会话已损坏,但是即使刷新(F5),登录页面仍然停留。

Problem 2: session destroyed, but logged in page stays even as I refresh (F5).

推荐答案

对于htaccess,我建议:

For htaccess I suggest:

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

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

And know that when you kill session CI will create a new 1 on your next Page load (in your case on the redirect) .. Session isn't just for user logins.

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

Don't forget at app/config/config.php to set

$config["index_page"] = '';

这篇关于会话销毁并定向后,Codeigniter无法刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆