Different cookies expire time between browser and local server - cookies

We use cookie to remember user's login status. The cookie's expire time in my code is all right, but when redirected to another page, the cookie is missing. Then I modify the code, add 100 years to the cookie's expire time. Finally, the browser shows the expire time is 2115-07-23.
Here is the code picture and local time:
A few minutes later,the system broken down. When I open the program again, it is all right! It's unbelievable!

Related

Prevent website (Moodle) from auto deleting login cookie

My university's Moodle site (https://moodle.hu-berlin.de/login/index.php) asks me to log in every time I open the browser. It is rather annoying to have to click this every time, even with the browser autofilling my details.
I think I would not have to log in every time if a cookie was kept on my computer:
"[The Moodle site in question] uses one session cookie, usually called MoodleSession. You must allow this cookie in your browser to provide continuity and to remain logged in when browsing the site. When you log out or close the browser, this cookie is destroyed (in your browser and on the server)." ("?" popup on the Moodle login page)
Is there a way to manually save the cookie on my computer and thereby avoid having to log in every time?

How to expire F5 APM session on browser close with alternate timeout

We are using the F5 APM to control access to our webapp, but are having some issues regarding expiration rules.
The scenario we want is that the cookie expires 12 hours after creation, or upon browser close, whichever comes first.
Despite our efforts, it would seem that we only have 1 of two options
set the cookies "Expires" property to 12 hours (or max-age)
don't set the "Expires" property at all
The first option successfully allows for the cookie to expire after 12 hours, but if the browser closes, the cookie is persisted until that time, so only one of the 2 conditions is met.
The second option will expire the cookie on browser close, but will not expire if the browser is open for 12 hours or more.
Is there a setting with the F5 APM that will expire the session on the F5 side, while the cookie can remain a session cookie on the browser side?
The best way to accomplish what you are trying to do with APM is to use a session cookie for the APM MRH cookie, and then set the Maximum Session Timeout setting to 12 hours (the value is set in seconds) on the Access profile under Properties in the Settings section (on version 11.x, may be in a slightly different place on v10.x). This will do exactly what you are trying to do.

How to extend Cookie expiry from user's last activity?

How to extend cookie expiry date from last activity which user has done?
Lets take an example, by default, cookie is set for 30minutes after user login.
userA do login at 1PM, hence given cookie will expire at 1.30PM.
Problem with this scenario is that if userA is doing something very important activity in app, then when he click on submit form on any internal link, he will get redirected to login.
Hence he loses his work which he as done.
What I want to have is when userA log in at 1PM (First activity), then at first, cookie will expire at 1.30PM.
After that userA become idle, that means he does not click anywhere, he just leave his computer and come back again after 15 minutes i.e. at 1.15PM and starts using php portal, then cookie expiry should become 1.45PM
How to do that? I found script PHPmyadmin has done same thing. It leads to expiration of cookie when user become inactive for more that 1440 seconds.

Detecting user logout on browser close in Django

we have a web service for some numerical computing. It has a registered mode, in which a user has to register to have its results sent by mail.
We would like to keep track of how long the user stays logged. The login time is written in the database upon successful registration. Registration in not permanent, it's just for the purpose of single session and is used for acquiring the user email.
There are a few situations possible:
User logs out normally via the logout button.
Simplest solution. Write the time and logout in the database, and delete session.
User logs out by session expiry.
I'm planning on having a script which would check all the database entries which don't have a set logout time and if current time - login time > expiry time write logout time in a database as login time + expiry time.
User logs out by browser close.
The sessions have a get_expire_at_browser_close() set to True. But i don't know how can the server detect browser closure.
Ideas, critics, comments?
In django session middleware these lines control session expiration if we want that SESSION_EXPIRE_AT_BROWSER_CLOSE:
if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE:
max_age = None
expires = None
Server doesn't have to do detect anything as cookie that has no max_age or expires set should be deleted on the client side, according to this page:
By setting either of these, the cookie will persist until its time runs out, otherwise—if you set neither—the cookie will last until you close your browser (a “session cookie”).
Edit:
One way of tracking how long user was online is by using javascript that will ping server every now and then. It will happen only as long as the user has page opened in browser and on every ping server should update last seen online value for the user.
When user closes browser session is over. Next time user logs in server can calculate duration of his last visit as last seen online - last login time.
Simpler solution without using any javascript: last seen online could be updated on every user request using simple custom middleware.

Should I return the cookie in every web response?

When a user login in my website, it returns a cookie with two hours expire. The cookie is not returned in following calls, so after two hours the cookie expires even when the user is still using the website, and then redirected to the login page.
So I think I know the solution, but is it a good practice return the cookie with the "expire" updated in every call?
Cheers.
It's not a huge deal to set a session cookie in every server response, especially since the client is already sending it to the server in every request.
However, you can do better than that. If the client comes in with a cookie that's bound to expire, say, less than 1 hour and 50 minutes from now, you can send them a new cookie that's set to a new, 2-hour expiration date. You can easily keep track when a client cookie is set (and is therefore bound to expire) in your session handling code.
It boils down to why not? It solves the timeout problem, and has no drawbacks.
The only side effect is the additional bandwidth necessary to transfer the cookie, but this is completely negligible. If you do care about that bandwidth, only resend the cookie every n minutes.