How can I check if the user's session has expired or not? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can I check if the user's session has expired or not?

In my Airline Booking Program, I now wish to make a session timer. I want to offer the user n minutes for booking, and then cancel booking if the user hasn't reached the last option till then... So I wish to count the number of seconds taken during the data fill... I think I have to use <chrono> for this, but I have no idea how to use it... How can I create this timer? Also, I want to print the time left in the session to end to be printed alongside in the console, n-executed time. How to display that?

9th Jun 2017, 8:20 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
8 Answers
+ 4
as the user logs in save the time in a Session variable e.g. loginTime. on each page load check if the current time - loginTime is greater than the timeout you want to set: If true handle the expired session the way you prefere. Else reset the login time assigning the current time to the loginTime variable.
9th Jun 2017, 11:37 AM
seamiki
seamiki - avatar
+ 4
You can create use JavaScript for that. look at setTimeout and/or setInterval.
9th Jun 2017, 11:40 AM
seamiki
seamiki - avatar
+ 4
Sorry I thought you were doing a web interface... The concept is the same. have a look at time.h http://www.cplusplus.com/reference/ctime/ you can use a label to show the time value
9th Jun 2017, 11:44 AM
seamiki
seamiki - avatar
+ 1
@seamiki But how will I increase it after every second?
9th Jun 2017, 11:38 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
@seamiki JS in C++? Is it possible?
9th Jun 2017, 11:41 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
@seamiki Thank You very much!
9th Jun 2017, 1:27 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
@kinshuk did you write your code after seamiki advice.if yes then kindly give the link to your program. well i did a program based on that but it not working properly. https://code.sololearn.com/cpJA2R6nU1da/?ref=app
11th Jun 2017, 8:20 AM
NIKHIL MURARKA
+ 1
@NIKHIL Mine's not working as well, yet...
11th Jun 2017, 8:23 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar