Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP cookie with same name but different paths

Tags:

php

cookies

yii

I want to check a cookie with name "subscription" and there are 3 cookies with this name but has different paths as follows path 1 is / path 2 is /customer/checkout/ path 3 is /customer/register/

now if i want to apply an if condition if subscription is set then the condition works only for path 1.How do I make it work for all three paths???

like image 536
user3239364 Avatar asked Feb 15 '26 08:02

user3239364


1 Answers

I don't think you can reliably check the path of a cookie in PHP (or any serverside language for that matter) as most or at least some browsers don't send the path for the cookie. They only send key-value pairs.

If reliability/cross browser support isn't a must, you could check if the path of the cookies is send with the request headers. Use a method like

<?php

foreach (getallheaders() as $name => $value) {
    echo "$name: $value\n";
}

?>

http://www.php.net/manual/en/function.getallheaders.php

like image 142
Bob Brinks Avatar answered Feb 16 '26 22:02

Bob Brinks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!