Codeigniter cannot refresh page after session destroy and direct

≡放荡痞女 提交于 2019-12-24 15:11:40

问题


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

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> 

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');
            }


        }

Below is the function that suppose to kill the current session and redirect to dashboard page.

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


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

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?

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


回答1:


For htaccess I suggest:

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

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.

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

$config["index_page"] = '';


来源:https://stackoverflow.com/questions/19398871/codeigniter-cannot-refresh-page-after-session-destroy-and-direct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!