Question

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).

Was it helpful?

Solution

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"] = '';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top