Example #1
0
 public static function get()
 {
     if (!self::$localdata_obj instanceof localdata) {
         self::$localdata_obj = new self();
     }
     return self::$localdata_obj;
 }
Example #2
0
      <p><strong>Create Object</strong> - <span class="mark">$localdata = localdata::get();</span> <br />
      <p><strong>Store</strong> - <span class="mark">$localdata("name", "value");</span> or  <span class="mark">$localdata->name = "value";</span><br />
      value can be integer, string, object, array <br />
      $localdata("name", array(1,2,3,4,5)); <br />
      $localdata("name", array("name" => "John Dow", "email" => "*****@*****.**")); </p><br />
      <p><strong>Read</strong> - <span class="mark">$localdata("name");</span> or <span class="mark">$localdata->name</span></p>
      <p><strong>Delete One Item By Key</strong> - <span class="mark">$localdata->remove("name");</span> </p>
      <p><strong>Delete entire cookie</strong> - <span class="mark">$localdata->clear();</span> </p>
      <p><strong>Count Stored Items</strong> - <span class="mark">$localdata->count();</span> </p>
      <p><strong>Get/Set cookie configuration</strong> - <span class="mark">$localdata->config()</span> and <span class="mark">$localdata->config(Array('expires' => 'in days', 'path' => 'your new path', 'domain' => 'domain', 'secure' => true or false})</span> defaults are 'expires' => 365, 'path' => '/', 'domain' => NULL, 'secure' => NULL</p>
      <p><strong>Get/Set cookie prefix</strong> - <span class="mark">$localdata->prefix()</span> and <span class="mark">$localdata->prefix("new_prefix_")</span> default is "localdata_cookie_" </p>
      <input type="text" id="userInput" style="width:160px;" /><input id="write_to_local" type="button" value="write this to localdata" style="cursor:pointer; margin-left:10px;" /><h4>Local Data Object</h4><pre id="before_result"></pre>
      <h4>Local Data Object After Modification from Javascript</h4><pre id="result"></pre><h4>Local Data Object After Modification from PHP</h4><pre id="php_result">
  <?php 
include 'localdata.php';
$localdata = localdata::get();
$master_object = $localdata("master_object");
$master_object['php_data'] = array("name" => "John Dow", "email" => "*****@*****.**", "PHP-rand" => rand(1, 1000000));
$localdata("master_object", $master_object);
print_r($localdata("master_object"));
?>
      </pre>
      </td>
    </tr>
</table>
</div>
<script type="text/javascript">
/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL