473,408 Members | 2,813 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,408 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 25042
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.