I want to be able to keep a PHP session, even after the browser has been closed. I know on this question, they suggested using the session_set_cookie_parameters() parameter, but I am unable to find a working example of this that doesn't expire and works across all directory on my domain. If someone could help out, it would be amazing.
Asked
Active
Viewed 240 times
0
-
I wanted to avoid using cookies because they are client side, and therefore can be edited or modified by the client; henceforth making it easier for people to gain unauthorised access to an others account. – Harry Jan 14 '13 at 03:54
-
so store the session id in the cookie and recreate when they come back – Jan 14 '13 at 04:04
-
That's what I ended up doing. Thanks. :) – Harry Jan 14 '13 at 06:44
2 Answers
1
Session stands for "until browser is closed". Session is something that expires. If you don't want it to be expired, you're probably don't want a session at all. You better read on cookie too. I guess that's what you need.
But You can use session_set_cookie_parameters() to give the session cookie a non-zero lifetime before starting the session, or set session.cookie_lifetime to non-zero.
Remeber session_set_cookie_params()
needs to be called before session_start() for every single page request. Read more
Code:
<?php
session_set_cookie_params(30 * 60, "/");
session_start();
print_r(session_get_cookie_params());
?>
Output:
Array ( [lifetime] => 1800 [path] => / [domain] => [secure] => )
Explanation:
Sets the cookie to expire after 30 minutes and be available anywhere on the site.

Techie
- 44,706
- 42
- 157
- 243
-
-
yes it could be, it depends on your requirement. Read the links which will helps you to figure out what you need – Techie Jan 14 '13 at 03:58