benedmunds / CodeIgniter-Ion-Auth

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

login loop #1144

Closed Reserford1991 closed 6 years ago

Reserford1991 commented 7 years ago

Hello everybody I have a problem with login. I've been redirectred to login page in a loop. As far as I understood, smth is wrong with session and cookies, because flag of successful login is not transferred to session. Thanks in advance.

benedmunds commented 7 years ago

Are you redirecting after the login? Also what are your config settings for the session/cookies?

Reserford1991 commented 7 years ago

Hi. Yes, am being redirected after login. Here are my configs or session/cookies:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = false;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = false;
$config['cookie_prefix']    = 'serpfarm_';
$config['cookie_domain']    = '.' . $_SERVER['SERVER_NAME'];
$config['cookie_path']      = '/';
$config['cookie_secure']    = false;
$config['cookie_httponly']  = false;

Before this issue I had another problem. When I tried to login, I was getting this message from database:

Error Number: 1062
Duplicate entry '1508395728' for key 'PRIMARY'

INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('q63dbs867jssnf397eo14fbdscevai3o', '127.0.0.1', 1508395728, '__ci_last_regenerate|i:1508395728;FBRLH_state|s:32:\"d60d072a1bf2fdd7a99d884cf389c1e3\";')

Filename: C:/OSPanel/domains/sitemanager/system/database/DB_driver.php

Line Number: 691

In database table ci_sessions I had timstamp column as primary key. After I made id column primary key, I managed to load login page, but now I have login loop after I enter correct login and password. I also noticed one interesting thing. When I load page, I get two records in ci_sesions table. I mother project, where I used Codeighniter, There was only one recording for each session. Maybe this is the real problem, which causes login loop.

benedmunds commented 7 years ago

Make sure it's not related to the code in the example controller that redirects the user if they arent an admin.

Reserford1991 commented 7 years ago

Ok. Thanks a lot, I'll see about that. Can this problem be related to .htaccess of my local server? I just took standard for codeighniter and used it on my website.

benedmunds commented 7 years ago

Maybe yea... Try adding the index.php and see if you get the same results.

Reserford1991 commented 7 years ago

Actually I already did that, but no result yet. As far I understood during today's debugging, somehow CI makes several records to database at the same time. Tomorrow I'll debug this problem and let you know about results. One more possible source of the problem is my OS - windows 7 (don't laugh too much). Hopefully tomorrow I'll switch back to Linux or Mac again.

Reserford1991 commented 7 years ago

By the way, one more question. On which version of PhP you made this plugin. If I use 7.1 or 7.0, won't it cause any problems?

benedmunds commented 7 years ago

I'm not aware of any issues in 7.x. You should see a PHP error if it's related to the version.

Reserford1991 commented 7 years ago

Ok. I'll try that too. Thanks a lot for valuable tips.

benedmunds commented 7 years ago

No problem!

avenirer commented 7 years ago

@Reserford1991 please, also make sure you have latest version of CodeIgniter.

benedmunds commented 6 years ago

Any update?

Reserford1991 commented 6 years ago

Hi. I solved this problem. Solution was easy - just downgraded PHP to version 7.0.8 Before that I tried to work on version 7.1.8 Had problems with ci_session. Now those problems are gone. So I think you can close this issue now.

benedmunds commented 6 years ago

Thanks, closing.

What version of CodeIgniter were you on?

Reserford1991 commented 6 years ago

echo CI_VERSION gives me 3.1.0 but as I understood it is some issue with PHP itself and its bugs with session handling in latest versions.

benedmunds commented 6 years ago

If you get a chance to circle back to this I’d be interested in if PHP 7.1 works for you with CI3.1.6

Reserford1991 commented 6 years ago

I'm sure I will, because now I'm working with project, which uses your plugin. This product will be used by hundreds of users and no doubt that some them will use php 7.1.