1
votes

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');
1
Do you mix PHP Sessions with Cookie Sessions? PHP Sessions should be of a short lifetime.Markus Zeller
If you want to have your sessions expire you don't have to maintain that time yourself. stackoverflow.com/questions/520237/… has a good detail on how to do it correctly.hppycoder
@MarkusZeller I think yes. Please check the updated.Roshan Zaid
I am not sure if it is working setting cookies and then do a redirect within the same header scope. So I guess, the cookies will never be set.Markus Zeller
The other thing I guess is completely wrong using PHP superglobal $_SESSION. You should $_COOKIE instead.Markus Zeller

1 Answers

0
votes

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.