Initial creating then deleting a cookie works, but can't recreate it afterwards

HelpNeeder

I need to create and delete cookies.

The issue is that I can create, then delete cookie, but after previously deleted cookie I am not able to create a new one. Why?

It works once more after I clear the cache of the browser.

Creating cookie and redirecting to test page:

<?php
    $cookie_name = 'name';
    $cookie_time = 2000000000;
    $cookie_path = '/';
    $cookie_value = uniqid();

    setcookie($cookie_name, $cookie_value, $cookie_time, $cookie_path);

    echo '<script> window.location.assign("test.php"); </script>';
?>

Deleting a cookie and redirecting to test page:

<?php
    $cookie_name = 'name';
    $cookie_path = '/';

    setcookie($cookie_name, '', time() - 3600, $cookie_path);

    echo '<script> window.location.assign("test.php"); </script>';
?>

The test page just has print_r($_COOKIE); in it.

What am I doing wrong here? Is the name of the cookie an issue? Is it browsers limitation?

I need to be able to create and delete the cookie whenever I need to.

I tried to avoid the cache by using this code:

<?php
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?> 
Tigger

The problem may be the browser is caching the page request independently of what the server is telling it to do.

There is a simple trick to get around this. Adding a changing variable to the query string will make the page request unique each time. This will also force the browser to re-load the page even when cached.

For example, add the following to the address bar / page request:

?abc=123

And change the number value each time. Alternatively you can even use a timestamp like so:

?<timestamp>

This will force a standards compliant browser to fetch the page each time.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating unique partition keys can't be used afterwards for other data

From Dev

Can't rename MSI afterwards

From Dev

Can't recreate mysql user

From Dev

Hardware won't boot, works fine afterwards as a USB disk

From Dev

Can't create svg line, but creating svg circle works fine

From Java

Homebrew installs nvm but nvm can't be found afterwards?

From Dev

GoogleApiClient: Can't manually connect and perform signOut afterwards

From Dev

Can a Express session works without cookie?

From Dev

setcookie works but doesn't save in $_COOKIE

From Dev

Can't recreate and schedule Timer gain after cancelling it. Why?

From Dev

WPF ListBox binding works at first, but not afterwards

From Dev

Can't set a cookie on PostConstruct

From Dev

PHP: Can't Set Cookie

From Dev

Can't set cookie in laravel

From Dev

Can't understand the behavior of deleting vars in JavaScript

From Dev

Can't created button_to for deleting

From Dev

Can't apt update after deleting proxy

From Dev

Is deleting a cookie in Javascript Synchronous?

From Dev

$.removeCookie is not deleting cookie in Chrome

From Dev

Deleting a cookie with value NULL

From Dev

Session cookie not deleting

From Dev

Cookie not deleting or changing

From Dev

Can't make Share works

From Dev

Can't figure out what happened to file, and can't recreate it in eclipse

From Java

Creating a calculator but can't exit

From Dev

Creating a calculator but can't exit

From Dev

Deleting and creating body in libGDX

From Dev

Creating and Deleting Pictures/Screenshots

From Dev

Why InitializeComponent not works for recreate events if they were removed