Reputation: 3504
I am trying to implement the logout procedure for my website.
When the user clicks the sign out button I redirect him to the following home
controller script.
http : // mydomain/php/ci/index.php/index/?logout=set
And in my home controller index
function I check if logout=set then destroy all sessions.
echo @$_GET['logout'];
exit();
if(@$_GET['logout'] == "set")
{
unset($_SESSION['userid']);
@$_SESSION = array();
@session_unset();
@session_destroy();
}
But when I reach here nothing gets printed because the logout param is not passing. I see the following url when i get here on clicking the sign out button.
http://localhost/php/ci/home/
Why is this happening?
Upvotes: 0
Views: 4833
Reputation: 4686
Codeigniter has deafault INPUT class which is loaded.. Check it.
http://ellislab.com/codeigniter/user_guide/libraries/input.html
Upvotes: 1
Reputation: 1227
You can get all the get
data with CodeIgniter
like this:
var_dump($this->input->get());
However, don't use the index
method to log users out, but make a method for it, like i.e. this:
class Users extends CI_Controller() {
public function index() {
// Index stuff here
}
public function logout() {
// Your check if a user is logged in, instead of the dirty @
if(isSet($_SESSION['userid'])) {
unset($_SESSION['userid']);
}
redirect();
}
}
Then in your view make a link like this:
site_url("users/logout");
You will want to use the CodeIgniter session handler for this, but this is just a quick solution for your problem. I can advice you to read the CodeIgniter manual. As your "solution" for logging out is quite dirty and does not fit the MVC principle
Upvotes: 3