PHP Classes
elePHPant
Icontem

Local Data: Store multiple values in a single cookies

Recommend this page to a friend!
  Info   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2012-07-03 (4 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 563 All time: 5,170 This week: 1,099Up
Version License PHP version Categories
local-data 1.0Artistic License5.0HTTP, PHP 5
Description Author

This class can store multiple values in a single cookies.

It can set and get multiple values that use cookies to be shared between different server side scripts.

The values are stored in cookies encoded in JSON format so they can be easily accessed on the browser side JavaScript code preserving the original value data types.

A JavaScript library is provided to set and get values stored this way in cookies.

Innovation Award
PHP Programming Innovation award nominee
July 2012
Number 4


Prize: One downloadable copy of PhpED Professional
Cookies are usually used to share persistent information between the browsers and the Web server that pertains to a given user.

Usually cookies are stored as a single text value associated to cookie name value.

This class can extend the use of cookies so a single cookie can contain multiple values of different types besides text strings.

It is meant to be used together with JavaScript component that provides the same functionality on the browser side, so you can set and get values in cookies on the server side that can be accessed on the browser side and vice-versa.

Manuel Lemos
Picture of Pavel Kukov
Name: Pavel Kukov <contact>
Classes: 1 package by
Country: Bulgaria Bulgaria
Innovation award
Innovation award
Nominee: 1x

Details
Sample usage for localdata.js 
=============

* Store - $.localdata("name", "value"); 
value can be integer, string, object, array 
$.localdata("name", [1,2,3,4,5]); 
$.localdata("name", {name: "John Dow", email: "john@company.com"}); 
 
* Read - $.localdata("name"); 
* Delete One Item By Key - $.localdata.remove("name"); or $.localdata("name",null,{expires:-1}); 
* Delete entire cookie - $.localdata.clear(); 
* Count Stored Items - $.localdata.count(); 
* Force Reload - $.localdata.reload(); 
* Get/Set cookie configuration - $.localdata.config() and $.localdata.config({expires: 'in days', path: 'your new path', domain: 'domain', 'secure': true or false}) defaults are expires: 365, path: '/', domain: '', 'secure': '' 
* Get/Set cookie prefix - $.localdata.prefix() and $.localdata.prefix("new_prefix_") default is "localdata_cookie_" 
 
PHP: Sample usage for localdata.php 
=============

* Include - include('localdata.php');  
* Create Object - $localdata = localdata::get();  
 
* Store - $localdata("name", "value"); or $localdata->name = "value"; 
 value can be integer, string, array  
$localdata("name", array(1,2,3,4,5));  
$localdata("name", array("name" => "John Dow", "email" => "john@company.com"));  
 
* Read - $localdata("name"); or $localdata->name 
* Delete One Item By Key - $localdata->remove("name");  
* Delete entire cookie - $localdata->clear();  
* Count Stored Items - $localdata->count(); 
* Get/Set cookie configuration - $localdata->config() and $localdata->config(Array('expires' => 'in days', 'path' => 'your new path', 'domain' => 'domain', 'secure' => true or false}) defaults are 'expires' => 365, 'path' => '/', 'domain' => NULL, 'secure' => NULL 
* Get/Set cookie prefix - $localdata->prefix() and $localdata->prefix("new_prefix_") default is "localdata_cookie_"  
  Files folder image Files  
File Role Description
Files folder imagejs (2 files)
Accessible without login Plain text file index.html Doc. index.html
Plain text file index.php Class index.php
Plain text file localdata.php Class localdata.php
Accessible without login Plain text file README Doc. README

  Files folder image Files  /  js  
File Role Description
  Accessible without login Plain text file jquery-1.7.2.min.js Data jquery-1.7.2.min.js
  Accessible without login Plain text file localdata.js Data localdata.js

 Version Control Unique User Downloads Download Rankings  
 0%
Total:563
This week:0
All time:5,170
This week:1,099Up