A best-practice for cookies is to minimize their use. For instance, limit your cookie usage to just remembering the session id, and then store your data on the server side. In the EU, cookies are subject to legal regulations, and using cookies for almost anything but session ids require explicit client consent.
Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.
appname_meaningfulname
Keep in mind that this cookie is sent with every request, so imho, just use the smallest name you can, and document your code nicely.
It should be something that avoids naming conflicts with arbitrary _GET and _POST params you might be using, since _REQUEST wraps all three global arrays (!), with precedence depending on how your variables_order setting is set in php.ini. In other words, if you have a _COOKIE named "x" and a querystring param named "x", and you ask for $_REQUEST["x"], you get the cookie value when you might want/expect the GET param. This is especially problematic if your cookies are scoped to your website root "/", and not to the folder where they are consumed.
So I say, two best practices:
I use whatever style the coding standards for the project call for.
Generally I prefer camelCase for naming schemes, but whichever one pays the bills is the one I'll go with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With