1

your are setting some specific headers with the same name multiple times. For example

header("Set-Cookie: Foo=bar");
header("Set-Cookie: Bar=foo");
header("Set-Cookie: Baz=bob");

Afterwards you like to delete only "Set-Cookie: Bar", but not the other ones. How to do this?

header_remove doens't work here becaue you can specify the name "Set-Cookie", but not specific the Cookie "Set-Cookie: Foo".

1 Answer 1

2

It's not nice, but it works:

The solution is to copy all headers, delete all, filter and create again.

$headers = headers_list();
header_remove(); // removes all headers
foreach($headers as $h) {
    if (!preg_match("/^Set-Cookie: Bar$/", $h)) {
        header($h);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.