473,287 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Get cookie expiry time

Hi,

I am using cookies to keep track if a user is logged into my system,
and would like to display the time that the user has left logged in.
One solution is to display the time left until the cookie expires.

Does anyone know how to retrieve the expiry time of a particular
cookie?

TIA

Jeff

May 2 '06 #1
6 24999
If the above is not possible, then I suppose one solution is to store
the expiry time in an additional cookie.

May 2 '06 #2
On Tue, 02 May 2006 03:05:15 -0700, mymatebob wrote:
If the above is not possible, then I suppose one solution is to store the
expiry time in an additional cookie.


Or re-set the cookie for a known expiry time on every page view (say ten
minutes and 20 seconds) then countdown in Javascript for ten minutes (the
extra 20 seconds is grace period and to allow for the page to
download/Javascript to start).

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 2 '06 #3
Sounds a bit overly complicated! But an interesting solution.

It seems strange that there's no method in PHP for obtaining the cookie
expiry time. Ah well. In the mean time I have stuck with the "storing
expiry time in another cookie" method. Suppose I could add a Java
Script function to check the values every second to produce a real time
"time left until log out" counter.

Many thanks for the response!

Jeff

May 3 '06 #4
On Wed, 03 May 2006 02:32:36 -0700, my*******@googlemail.com wrote:
Sounds a bit overly complicated! But an interesting solution.
Not that complex though, it's only a matter of iterating through $_COOKIE
and resetting each one with a known expiry time (strtotime("+10 minutes
and 20 seconds")). You could do this in a single file and automatically
use it on every page using php_value auto_prepend_file in the Apache
virtualhost.
It seems strange that there's no method in PHP for obtaining the cookie
expiry time.
It's not really strange, if you examine the HTTP spec (or watch HTTP
headers using Firefox's Live HTTP Headers) you'll find the browser doesn't
send back the expiry date to the server, only the name and value.
Therefore it's not strange that PHP can't obtain the information, it's
never told (and it can't just remember what it set because it could have
been changed with Javascript or by editing the cookies.txt file).
Ah well. In the mean time I have stuck with the "storing
expiry time in another cookie" method. Suppose I could add a Java Script
function to check the values every second to produce a real time "time
left until log out" counter.

Many thanks for the response!


You're welcome.

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 3 '06 #5
Ah! That IS a good solution. I was thinking of setting a default expiry
of 4 hours, but with your solution, the cookies keep in date as long as
the user is actively using the website - much more user friendly.

Thanks for explaining the missing functions I was looking for in PHP. I
saw the cookie expiry date in the "View Cookies" Firefox extension and
just assumed the value would be readily available somehow.

Cheers

Jeff

May 4 '06 #6
On Thu, 04 May 2006 00:12:32 -0700, my*******@googlemail.com wrote:
Ah! That IS a good solution. I was thinking of setting a default expiry of
4 hours, but with your solution, the cookies keep in date as long as the
user is actively using the website - much more user friendly.

Thanks for explaining the missing functions I was looking for in PHP. I
saw the cookie expiry date in the "View Cookies" Firefox extension and
just assumed the value would be readily available somehow.


You're more than welcome mate, best of luck with your project.

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires =...
1
by: | last post by:
How does one read and write the cookie expiration date. At the moment my code is returning a value BUT a garbled value: '//Write cookie... Response.Cookies("Propsect").Expires = Date() + 1 ...
6
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone...
1
by: Hardeep Rakhra | last post by:
Hi i have a snippet of JS that i want to change so that the cookie it creates lasts only 48 hours. (or any other length of time i decide, but 48hours seems right for now) Only thing i can't...
6
by: Ray | last post by:
Below is the code to save the cookie and set the expiry date of the cooki Response.Cookies.Value ="Hello" DateTime dt = DateTime.Now TimeSpan ts = new TimeSpan(0,0,10,0) Response.Cookies...
15
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
0
by: mymatebob | last post by:
Hi, I am using cookies to keep track if a user is logged into my system, and would like to display the time that the user has left logged in. One solution is to display the time left until the...
0
by: robert | last post by:
I have noticed in .net 2 that when authenticating a user, setting the cookie using either redirectfromloginpage or setauthcookie, specifying true for the persistent parameter that the cookie is...
1
by: sazan | last post by:
Hi, I am new in java, i needed help in setting the expiry time for the session. I need the session to expire after 3 minutes, then show a table of the pages i visited during the 3 minutes and...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.