PHP Classes

File: README.cookie_preferences

Recommend this page to a friend!
  Classes of Ken Stanley   Cookie preferences   README.cookie_preferences   Download  
File: README.cookie_preferences
Role: Documentation
Content type: text/plain
Description: Documentation with examples on how to use cookie_preferences
Class: Cookie preferences
Manage site user preferences stored in cookies
Author: By
Last change:
Date: 18 years ago
Size: 2,446 bytes


Class file image Download
Don't let the name fool you, cookie_preference is merely an API aimed at allowing you, the web developer, to easily implement user preferences (either directly, or indirectly) as quickly as possible. To do this I've developed this class, and even tested it on my own shopping cart. It's not a very complex script to implement, and it's error handling is at a minimum, allowing you the developer to be more elequent. If a preference can not be set, read, or whatever, the class will just output a PHP Notice, which can be turned off in your app by using error_reporting(E_ALL & ~E_NOTICE). API Reference: void cookie_preference ( [preference_name[, cookie_expiry[, cookie_secure[, rot13]]]] ) Description: Yes, this is the contructor, but it is worth mentioning because you can set up your default environment by passing certain arguements when creating your class object. preference_name is the name of the cookie that holds your preferences. cookie_expiry is the length of time you want your cookie to live. cookie_secure is for when setting secure cookies over HTTPS. rot_13 is to obfuscate your cookie using the rot13 encoding (has automatic support for PHP <4.2.0) Example: $prefs = new cookie_preferences("my_prefs", time()+3600, 1, true); bool preference_new ( preference_name, preference_value ) Description: Sets a new preference to your cookie, but only if it doesn't already exist. Returns TRUE on success, or FALSE on failure. Example: if ($prefs->preference_new('foo', 'bar') === FALSE) { trigger_error("Preference foo already exists"); } bool preference_update ( preference_name, preference_value ) Description: Updates an already existing cookie with a new value. Example: if ($prefs->preference_update('foo', 'bar') === FALSE) { trigger_error("Could not update preference foo"); } string preference_get ( preference_name ) Description: Returns the value of preference_name on success, and FALSE on failure. Example: if (($foo = $prefs->preference_get('foo')) == FALSE) { trigger_error("Could not read preference foo"); } Bug reports, suggestions, or even patches should be sent to me directly, so I can keep up with any and all development. Remember, if someone forks the code--and you use their fork--and it doesn't work; I can't help you. But, if you do use my code, and need any help (or whatever), you can shoot me an email at phpclasses (at) kennethpaul (dot) com. Happy coding! :)