473,882 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25188
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*******@googl email.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_fi le 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*******@googl email.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
19903
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 = Date().toLocaleString(); Response.Cookies("Test").Expires = Date().toString(); Response.Cookies("Test").Expires = Date().toUTCString();
1
11143
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 '//Read cookie... ExpDate = Request.cookies("Propsect") Response.write "Prospect expiry date: " & expDate & "<br>"
6
12966
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 here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
1
2096
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 figure out how it specifies the expiry time. Thanks! Hardeep
6
3841
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 .Expires = dt.Add(ts); Below is the code to retrieve the stored cookie if (!Page.IsPostBack)
15
3661
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 HttpCookie.Expires property, but property value is the time of day on the client. How can I possibly know client local time ?
0
1120
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 cookie expires. Does anyone know how to retrieve the expiry time of a particular cookie? TIA
0
1745
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 persistent with an expiry time of 30 minutes from now, unless you have specified a timeout attribute in the forms element in the web.config. Quoting from msdn: "timeout: Optional attribute. Specifies the time, in integer minutes, after which...
1
1764
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 also show how many time each page was visited. I would appreciate any help. Thanks. sazan.
0
9931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9777
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11108
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10725
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10830
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7956
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.