PHP code example of dvv / macaron

1. Go to this page and download the library: Download dvv/macaron library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dvv / macaron example snippets


// everlasting token
$token = \Macaron\Macaron::encode('whatever PHP can serialize', 'ver1STrongsikret');
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret');
// 'whatever PHP can serialize'

echo \Macaron\Macaron::decode($token . 'FORGED!', 'ver1STrongsikret');
// false
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret' . 'LEAKED!');
// false

// expiring token
$token = \Macaron\Macaron::encode('whatever PHP can serialize', $secret, '+3 seconds');
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret');
// 'whatever PHP can serialize'

sleep(3);
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret');
// null

// overriding serializer
class Pasta extends \Macaron\Macaron {

  static protected function serialize($data) {
    return json_encode($data);
  }

  static protected function unserialize($string) {
    return json_decode($string, true);
  }

}

$token = Pasta::encode('whatever JSON can contain', $secret, '+3 seconds');
echo Pasta::decode($token, 'ver1STrongsikret');
// 'whatever JSON ca contain'

sleep(3);
echo Pasta::decode($token, 'ver1STrongsikret');
// null