Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:57:39+00:00 2026-05-28T18:57:39+00:00

I have following requirements: create a cookie for server domain that cookie will expire

  • 0

I have following requirements:

  1. create a cookie for server domain
  2. that cookie will expire in x seconds say in 200 or 500 seconds.

Problem is, that clients can lag as much as many minutes behind server. On server side I am setting cookie as

setcookie($cooName,$cooVal,time()+500,"/");

but now if client computer is 500 seconds behind server, above code will effect into a cookie which will expire in 1000 seconds not 500 seconds.

I was thinking to send client’s time stamp to server and set cookie on that time. something like this:

setcookie($cooName,$cooVal,$_GET['clientTS']+500,"/");

But if client is 500 seconds behind, and if I set such a cookie which is backdated it does not get set. How to achieve a time sync between client and server in case of cookie expiry?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:57:41+00:00Added an answer on May 28, 2026 at 6:57 pm

    Unfortunately, Expires is an absolute date and depends on the user agent’s local date. As you have concluded correctly, this could lead to an inaccurate cookie expiry.

    This is also the reason why IETF’s first standardization of Netscape’s original proposal, replaced the absolute expiration date by a relative expiration date, the Max-Age attribute that specified the time in delta seconds from the point in time the cookie has been issued. RFC 2965, that obsoleted RFC 2109, did the same. Just as RFC 6265, that is currently the most recent specification for cookies.

    Cookies as per RFC 6265 do also allow to specify the expiry date by both a relative date using Max-Age and a absolute date using Expires, the latter primarily for backwards compatibility:

    If a cookie has both the Max-Age and the Expires attribute, the Max-Age attribute has precedence and controls the expiration date of the cookie.

    So you could write your own function that mimics this behavior:

    $maxage = 12345;
    $expires = date(DATE_COOKIE, time()+$maxage);
    header("Set-Cookie: $name=$value, Expires=$expires, Max-Age=$maxage, …");
    

    Here’s an example function:

    function set_cookie($name, $value=null, $maxage=null, $path=null, $domain=null, $secure=false, $httponly=false) {
        $cookie = rawurlencode($name) . '=' . rawurlencode($value);
        $attributes = array();
        if (!is_null($maxage)) {
            $maxage = intval($maxage);
            $attributes[] = 'Expires='.date(DATE_COOKIE, $maxage > 0 ? time()+$maxage : 0);
            $attributes[] = 'Max-Age='.$maxage;
        }
        if (!is_null($path)) {
            $attributes[] = 'Path='.rawurlencode($path);
        }
        if (!is_null($domain)) {
            $attributes[] = 'Domain='.rawurlencode($domain);
        }
        if ($secure) {
            $attributes[] = 'Secure';
        }
        if ($httponly) {
            $attributes[] = 'HttpOnly';
        }
        header('Set-Cookie: '.implode('; ', array_merge(array($cookie), $attributes)), false);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a requirement to create a data structure that has the following
I have the following requirements I have relational content stored in a SQL Server
Can someone recommend a hosted solution that answers the following requirements (I have seen
The Requirements I have a following table (pseudo DDL): CREATE TABLE MESSAGE ( MESSAGE_GUID
When we talk about security we have the following requirements: authentication integrity Non-repudiation Isn't
For a programming assignment, we have the following requirements: It needs to be a
I have the following password requirements: 1) Should be 6-15 characters in length 2)
I have a WCF Service with the following requirements: a) The client requests a
I have a need for a counter of type long with the following requirements/facts:
I have the following assignment for homework. Requirements Design a class called TokenGiver with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.