I have a problem's. I am working on a little cms. When I log in, everything is fine. but if I sit there, the session seems to require me to log in again after 3 minutes. so I tried to implement the remember me function. and they were also unlucky. it also requires me to log in.
in my functions I have the following snapshot of code.
function logged_in(){ if(isset($_SESSION['email']) || isset($_COOKIE['email'])){ return true; } else { return false; } }
Then I created another function, which, if a login is required on the page and yours is not registered, it will be redirected.
function require_loggin(){ if (logged_in()) {} else { redirect(ROOT_URI); } }
now on all pages that require loggin, I have this in the page title.
<?php require_loggin(); ?>
and this is my login details.
$email = clean($_POST['email']); $password = clean($_POST['password']); $remember = isset($_POST['remember']);
and finally my login.
function login_user($email, $password, $remember){ $active = 1; $connection = dbconnect(); $stmt = $connection->prepare('SELECT user_pwd, user_email, uid, username FROM users WHERE user_email = ? AND active= ?'); $stmt->bind_param('ss', $email, $active); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows == 1) { $row = $result->fetch_array(); $db_password = $row['user_pwd']; if (password_verify($password, $db_password)) { if($remember == "on") { setcookie('email', $email, time() + 86400); } $_SESSION['uid'] = $row['uid']; $_SESSION['email'] = $row['user_email']; $_SESSION['username'] = $row['username']; return true; } else { return false; } return true; } else { return false; } }
everything works without errors. login and logout are ok.
The problem is that after logging in, the default session dies after about 4 minutes if they don’t click the links. and the function to remember me will not work. I read some where the default session should last about 30 minutes. but the session requires you to log in after 4 minutes without moving around the site.
Someone mentioned to me about the garbage collection, but I must admit that I completely lost it.
I am still pretty new to php and I want to find out the correct path in the wrong way. my project works fine, I just can’t get the user to log in or be able to remember me.