r/PHPhelp • • Aug 24 '26

PHP Default Session Management

I need to manually configure user side cookie expiration and server side session data expiration separately. also I can't find a way to update existing session data expiration since I update the expiration value of the cookie in some requests to keep user logged in.

$sessiontime = (60 * 60) * 12; //12 hours in seconds

//make sure at least 12 hours session never touched by session GC.
ini_set('session.gc_maxlifetime', $sessiontime);

....

session_set_cookie_params($sessiontime);
session_start();


//refresh session cookie time whenever we get request.
setcookie(session_name(), session_id(), [
    'expires' => time() + $sessiontime,
]);

am I missing something?

2 Upvotes

5 comments sorted by

View all comments

5

u/[deleted] Aug 24 '26

[removed] — view removed comment

1

u/AssistanceClean948 Aug 24 '26

thank you. I thinked this but using something different method when php provides such mechanism kinda weird but yeah.