benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.35k stars 1.14k forks source link

Hook function isn't functioning properly #1516

Closed gabe152006 closed 3 years ago

gabe152006 commented 3 years ago

Using branch 4 CI 4.1

Hello!

I'm trying to run a function using a hook right before the login() method:

...
// check to see if the user is logging in
// check for "remember me"
$remember = (bool)$this->request->getVar('remember');
$this->ionAuth->setHook("post_login_successful", "check_cookie", $this, "handleCookies", array());

Then my function:

public function handleCookies() {
     if(!isset($_COOKIE['test'])) {
          setcookie('test', 'FALSE', time() + (86400 * 30), "/");
          $this->ionAuth->logout();
          return redirect()->to('/login');
     }
}

The cookie is being created but the redirect and the logout function are being ignored

Am I approaching this in the wrong way?

Thank you!

benedmunds commented 3 years ago

This seems fine to me. Any errors? You could try a php redirect instead of the CI redirect and see if you get different results, I wonder if you don't have the CI functions available in this context for this reason...

benedmunds commented 3 years ago

Closing due to inactivity. Feel free to re-open if this is still an issue.