473,385 Members | 1,925 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,385 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 25038
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.