[eluser]airween[/eluser]
Hello everyone,
I'm new in CI, I see there are many question about login method, but I think those're too simple
So, what I want:
- there is an application
- it has many controller
- every controller needs authenticated session, except login and userreg
I don't want to include to constuctor of every controller's - I think it's dangerous, eg. I miss include it... Possible it would be better to route every query to login if it hasn't valid session, _and_ it's not login or userreg.
I've made this:
system/application/config/routes.php
Code:
session_start();
if (!isset($_SESSION['isAuthenticated']) || $_SESSION['isAuthenticated'] === false) {
$route['^.*$'] = "login";
}
NB: this is not the final solution.
My questions:
- is it a "good" solution? How could you make it another way?
- this has no effect when default controller has loaded. Why?
- should I use another mode to start the session instead of session_start()? How can I use CI Session class? NB: it must be loaded in router, not in controller!
- how can I redirect instead of re-route the URL in router?
Thank you:
a.