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 4231076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:55:50+00:00 2026-05-21T01:55:50+00:00

I am unable to get the cookie to unset. cookie set: (id, alias) setcookie(id,$data[‘id’],

  • 0

I am unable to get the cookie to unset.

cookie set: (id, alias)

setcookie("id",$data['id'], time()+3600*24*30);
setcookie("alias",$this->nombre, time()+3600*24*30);

cookies unset? (id, alias)

setcookie("id","-1",time()-315360000);
setcookie("alias","",time()-315360000);
unset($_COOKIE['id']);       // additional, but still no..
unset($_COOKIE['alias']);    //    "            "

What I am doing wrong?

  • 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-21T01:55:51+00:00Added an answer on May 21, 2026 at 1:55 am

    Using your example, I created this test:

    <?php
    
    ob_start();
    
    echo '<pre>';
    
    setcookie("id","0001", time()+3600*24*30);
    setcookie("alias","name", time()+3600*24*30);
    
    print_r($_COOKIE);
    
    if ($_COOKIE['id'] || $_COOKIE['alias']) {
        setcookie("id","-1",time()-315360000);
        setcookie("alias","",time()-315360000);
    }
    
    print_r($_COOKIE);
    
    ob_end_flush();
    
    ?>
    

    On the first load, it outputs:

    Array
    (
    )
    Array
    (
    )
    

    On reload:

    Array
    (
        [id] => 0001
        [alias] => name
    )
    Array
    (
        [id] => 0001
        [alias] => name
    )
    

    On second reload:

    Array
    (
    )
    Array
    (
    )
    

    So it appears your code is resetting the cookie on the roundtrip.

    EDIT

    The following:

    <?php
    
    ob_start();
    
    echo '<pre>';
    
    setcookie("id","0001", time()+3600*24*30);
    setcookie("alias","name", time()+3600*24*30);
    
    print_r($_COOKIE);
    
    if ($_COOKIE['id'] || $_COOKIE['alias']) {
        setcookie("id","-1",time()-315360000);
        setcookie("alias","",time()-315360000);
        unset($_COOKIE['id']);
        unset($_COOKIE['alias']);
    }
    
    print_r($_COOKIE);
    
    ob_end_flush();
    
    ?>
    

    Will either print:

    Array
    (
    )
    Array
    (
    )
    

    Or will print:

    Array
    (
        [id] => 0001
        [alias] => name
    )
    Array
    (
    )
    

    http://jfcoder.com/test/cookies.php (hit reload a few times)

    If you need to tell the browser to forget the cookie, use setcookie() with the time set back in time (I use at least 24 hours). If you need the $_COOKIES array to forget the value, use unset().

    EDIT

    There are two possible issues contributing here, one a subdomain mismatch on the cookie, and a path accessibility problem.

    For instance…

    If the url the visitor accessed was on a directory different from where the url that attempts to reset the cookie, you need to set the cookie with a path that will allow that cookie to be accessed (and reset) by other paths.

    setcookie('my', 'cookie', time()+3600, '/');
    

    Or to allow for paths contained within a subdirectory…

    setcookie('my', 'cookie', time()+3600, '/my/path/');
    

    If the url the visitor accessed was a subdomain (including www), but you want the cookie to be accessible to all subdomains, you need to give a wildcard to setcookie.

    setcookie('my', 'cookie', time()+3600, '/', '.example.com');
    

    Will allow urls from http://www.example.com, my.example.com, and sub.example.com to access and reset the cookie. Obviously, at this point too your path considerations need to be taken into account, since for a subdomain argument, you will need to include a path. / selects all subdirectories on the url, and . before the domain selects subdomains (although sub.sub.domains, I’m not sure).

    http://php.net/manual/en/function.setcookie.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to get the correct title for this, please change the title
I'm unable to get this jquery statement to work on page load but it
I need to set/get the cookies stored at first.example while browsing second.example , I
I am unable to get this to work: var proxyResponse = function(res) { return
I'm unable to get this working in IE, the second child doesn't remain in
I'm unable to get this function to work. The if always return false. What
I unable to get , Is this a activity or a customized dialog(If it
I am unable to get a highcharts plugin to render a chart in a
I have a seemingly simple problem though i am unable to get my head
I have the following code and I am still unable to get Hibernate to

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.