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: 16 years ago
Size: 396 bytes
 

Contents

Class file image Download
<?php
require_once("./Cipher.php");
$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'];
    echo
$cipher->decrypt($data, "a key", $iv);
}
?>