I'm using this code to set a login session from this answer
$lifetime=604800;
session_start();
setcookie(session_name(),session_id(),time()+$lifetime);
checking the resources tab from inspect element the session cookie should end on 2015-10-20
But I was signed out after closing the webpage in an hour and when I print the session I get " Undefined index: SESSION_NAME". So how to solve this problem and set the correct session lifetime to work?