I am working on a PHP role based application in which I have to maintain session as well. once the user is logged in he will be redirected to his interface where I manage session as The user id and password would match with the role. if it doesn’t match he would be redirected to the login as below.
if (!isset($_SESSION['user_login'])) { header("Location:index.php"); } else { if((time()-$_SESSION['expire']) > 365*24*60*60) { session_destroy(); } else{ //user would stay logged in } }
This also is interacted with a datatable in which whenever the session is being timedout, its throwing an error for the table which is :
datatables warning table id= – requested unknown parameter ‘0’ for row 0 column 0 tn/4
I think If I increase the session timeout, This wouldn’t be a burden. I tried to do in every possible way but all ended up with failures.
- Increasing php.ini session.gc_maxlifetime
- Overriding php.ini by pages as ini_set(‘session.gc_maxlifetime’, 31536000)
- Edit MultiPHP INI editor
Nothing seems like working except its local. Please advice.
Update (How session and cookies are structured from login):
if(!empty($_POST["remember_me"])) { setcookie ("user", $_POST["userid"], (time() + (10 * 365 * 24 * 60 * 60))); setcookie ("pass", $_POST["password"], (time() + (10 * 365 * 24 * 60 * 60))); } else { if(isset($_COOKIE["userid"])) { setcookie ("userid", ""); } if(isset($_COOKIE["password"])) { setcookie ("password", ""); } if (!session_id()) session_start(); $_SESSION['user_login'] = $userid; $_SESSION['expire'] = time(); header('Location: user_interface.php');
Advertisement
Answer
After so many attempts, What worked was we have to change the session path to “/tmp” on .htaccess. This is how it would seem to work if the app is hosted in a shared hosting.