Tuesday, 2 October 2012

session_set_save_handler

bool session_set_save_handler ( callable $open , callable $close , callable $read , callable $write , callable $destroy , callable $gc )
Sets user-level session storage functions
Since PHP 5.4 it is possible to register the following prototype:

<?phpclass MySessionHandler implements SessionHandlerInterface{
    
// implement interfaces here}
$handler = new MySessionHandler();session_set_save_handler($handlertrue);session_start();
// proceed to set and retrieve values by key from $_SESSION

5.4.0 Added SessionHandlerInterface for implementing session handlers and SessionHandler to expose internal PHP session handlers.

mcrypt_encrypt

string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] )

Encrypts plaintext with given parameters

Encrypts the data and returns it.


<?php
    $iv_size 
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256MCRYPT_MODE_ECB);
    
$iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);
    
$key "This is a very secret key";
    
$text "Meet me at 11 o'clock behind the monument.";
    echo 
strlen($text) . "\n";

    
$crypttext mcrypt_encrypt(MCRYPT_RIJNDAEL_256$key$textMCRYPT_MODE_ECB$iv);
    echo 
strlen($crypttext) . "\n";
?>