1

Google Chrome - Cookie Priority

As I have more than 20 cookies on my site I want to define priority to high for cookies set by my script so that other low and medium priority cookies set by analytics and ads will be deleted automatically when count reaches more than 20.  More than 99% of my users use google chrome so i don't care about other browsers. So, Is there a way to set cookie priority in php ?

Please help me out, Thanks in advance.

  • Check out this [link](https://stackoverflow.com/questions/61314996/how-do-i-set-a-cookie-priority-high-in-express-router) – Tugay Nov 03 '20 at 18:48
  • I want set this with php. – Gowthamraj Vungarala Nov 03 '20 at 19:17
  • There is no maximum limit on the number of cookies (unless something has changed recently), so I wouldn't concern myself with counting them. There is a general maximum size in bytes for overall cookies, per domain, however, and that's what I would target. The `priority` part of a cookie is only a [Google/Chrome](https://tools.ietf.org/html/draft-west-cookie-priority-00) thing currently, too, so I would recommend targeting bytes to make sure that important cookies survive across all browsers. – Chris Haas Nov 09 '20 at 14:25

1 Answers1

1

setcookie supports only a handful of standard cookie directives which is why passing Priority would throw an error. The only way I see to achieve that is through passing a Set-Cookie header using PHP's header function

header ("Set-Cookie: thisiskey=thisisvalue; Expires=Wed, 21 Nov 2020 07:28:00 GMT;  Domain=localhost; Path=/; priority=High");

As an extra info. setcookie internally uses header but thing is it carries out validation on the inputs you provide that is why it would throws an error for any unrecognized/arbitrary directive. What web browsers do is they read the cookie header and parse they too will accept what they think is a valid directive and simply ignore the rest which is why priority only works in chrome and its derivative browsers

Vinay
  • 7,442
  • 6
  • 25
  • 48