Forum Moderators: coopster

Message Too Old, No Replies

Ways of using $ COOKIE in procedural PHP

         

tpb101

1:33 pm on Apr 27, 2019 (gmt 0)

10+ Year Member



I am still learning PHP and I could use info on what are the most common usages / applications of $_COOKIE in the most common types of scripts like cms / blog / tube / forum / online store. I know how cookies work, but these actual applications (maybe like 10 or more) would be what I would actually need and then use the info for practicing it.

I basically need to “uncover” $_SESSION and $_COOKIE more, these actual usages of it, applications, in procedural PHP.

Thanks.

lucy24

5:58 pm on Apr 27, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you looking for cut-and-paste answers? That's the wrong approach; you need to look at it conceptually. In the case of $_COOKIE, the concept is: the exact details of page rendering will depend on the content of one or more cookies, which convey information about what the user has previously done on your site.

Simple real-life example (I’ve since dropped this, but it did what it was intended to do):
Consider a linked sequence of pages A B C D, intended to be viewed in order. A is the entry page; B links back to A and then forward to C; C links back to B and A and forward to D; D links back to all the others. The navigation menu will show the available pages.

But then: If user has previously seen page C, then page A will also link to C; if user has previously seen page D, then pages A and B will link to everything. It’s done by reading the value of a cookie (or simply checking for its existence) and then showing or not showing the specified menu item.

Make sure the site remains functional for users who, for any reason, do not retain cookies.

tangor

5:52 am on Apr 28, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure the site remains functional for users who, for any reason, do not retain cookies.


Or allow them in the first place.

Keep in mind that cookies are also coming under other potential regulations, such as GDPR ...