PHP Classes

File: example/cookie.php

Recommend this page to a friend!
  Classes of Nathan Lucas   Cipher   example/cookie.php   Download  
File: example/cookie.php
Role: Example script
Content type: text/plain
Description: Cookie example.
Class: Cipher
Encrypt and decrypt data with a single key
Author: By
Last change: Changed example with a more practical one.
Date: 15 years ago
Size: 396 bytes


Class file image Download
$cipher = new Cipher;

if (!isset(
$_COOKIE['c_data'])) {
$data = $cipher->encrypt("some data", "a key");
$iv = $cipher->getIV();

setcookie("c_data", $data, time()+3600);
setcookie("c_iv", $iv, time()+3600);
} else {
$iv = $_COOKIE['c_iv'];
$data = $_COOKIE['c_data'];
$cipher->decrypt($data, "a key", $iv);