Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie Unset Method #1

Open
phpcodingmaster opened this issue Nov 6, 2024 · 4 comments
Open

Cookie Unset Method #1

phpcodingmaster opened this issue Nov 6, 2024 · 4 comments

Comments

@phpcodingmaster
Copy link

Describe the bug

Cant remove a cookie with \Leaf\Http\Cookie::unset('cookiename');
Have to use alternative below.

To Reproduce

Steps to reproduce the behavior:

  • Set a cookie like the below.
  • \Leaf\Http\Cookie::set("cookie", '1234', [
    "expire" => time() + 86400, // Expire in 1 day
    "httponly" => true,
    "path" => "/"
    ]);

// Try to remove with the below, does not work!
\Leaf\Http\Cookie::unset('cookie');

However, the below removes the cookie. Changiing the expire time to be less than before.
This works, but it just looks ugly compared to doing this -> \Leaf\Http\Cookie::unset('cookie');

\Leaf\Http\Cookie::set("cookie", "", [
    "expire" => time() + 200,
    "httponly" => true,
    "path" => "/"
]);

Expected behavior

Cookie should be removed with \Leaf\Http\Cookie::unset('cookie');

@mychidarko
Copy link
Member

Hi @phpcodingmaster I'll check this out

@mychidarko mychidarko transferred this issue from leafsphp/leaf Nov 14, 2024
@mychidarko
Copy link
Member

@phpcodingmaster I've so far been unable to replicate this issue. Just to confirm, are you submitting a response before checking to see if the cookie was unset?

@phpcodingmaster
Copy link
Author

Hi @mychidarko

Thanks for checking. Nope.

@mychidarko
Copy link
Member

PHP doesn't update the cookie values in your application until a response is sent to the client. Since Leaf's cookie module is built on PHP cookies, it also inherits that behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants