3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function xor_encrypt($in) { $key = '<censored>'; $text = $in; $outText = ''; // Iterate through each character for($i=0;$i<strlen($text);$i++) { $outText .= $text[$i] ^ $key[$i % strlen($key)]; } return $outText; } // CALLED FIRST function loadData($def) { global $_COOKIE; $mydata = $def; // If data is in the cookie if(array_key_exists("data", $_COOKIE)) { // Get the data in rawform. base64 -> XORED -> json $tempdata = json_decode(xor_encrypt(base64_decode($_COOKIE["data"])), true); // outputs an assoc array with a key "showpassword" and "bgcolor" if(is_array($tempdata) && array_key_exists("showpassword", $tempdata) && array_key_exists("bgcolor", $tempdata)) { // If bg color looks like # + 6 of a-f then copy it over to mydata if (preg_match('/^#(?:[a-fd]{6})$/i', $tempdata['bgcolor'])) { $mydata['showpassword'] = $tempdata['showpassword']; $mydata['bgcolor'] = $tempdata['bgcolor']; } } } return $mydata; } // CALLED NEXT // go the other way function saveData($d) { setcookie("data", base64_encode(xor_encrypt(json_encode($d)))); } function decryptcookie($data){ $base64_decoded = base64_decode($data); $xored = xor_encrypt(base64_decode($data)); $json = json_decode(xor_encrypt(base64_decode($data)), true); $out = json_decode(xor_encrypt(base64_decode($data)), true); //////////////////////////////////////////////////////////////// echo "This is it:\n"; echo "HEXX: ". bin2hex($data)."\n"; echo "orig: ". $data."\n"; echo "base64 decoded: ".$base64_decoded."\n"; echo "xor: ".$xored."\n"; echo "json_decode: ".$json."\n"; echo "out: ". $out."\n\n"; //////////////////////////////////////////////////////////////// print_r($out); print_r(array_values($out)); echo "Type of based64:". gettype($base64_decoded)."\n"; echo "Type of xored:". gettype($xored)."\n"; echo "Type of json:". gettype($json)."\n"; echo "Type of out:". gettype($out); echo "\n****\n"; } ///////////////////////////////////////////// $defaultdata = array( "showpassword"=>"no", "bgcolor"=>"#ffffff"); // put the cookie data in the new data $data = loadData($defaultdata); // if the color is a valid hexcode then add it to the cookie if(array_key_exists("bgcolor",$_REQUEST)) { if (preg_match('/^#(?:[a-fd]{6})$/i', $_REQUEST['bgcolor'])) { $data['bgcolor'] = $_REQUEST['bgcolor']; } } saveData($data); $cook = "ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSRwh6QUcIaAw%3D"; $cook_alt = "ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSRwh6QUcIaAw="; decryptcookie($cook_alt); echo 'Hello World!';
based on 2v7fm
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0beta1
This is it: HEXX: 436c564c49683441534373434245386c41784d6163464d5a5632686456566f74456868554a514e56416d685352776836515563496141773d orig: ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSRwh6QUcIaAw= base64 decoded: UK"H+O%pSWh]UZ-T%UhRGzAGh xor: 66.Lmo:Nf:sFf}i!|3Va6?Caw&@gk> 7){3"lV0 json_decode: out: Warning: array_values() expects parameter 1 to be array, null given in /in/KEkNK on line 66 Type of based64:string Type of xored:string Type of json:NULL Type of out:NULL **** Hello World!
Output for hhvm-3.15.4
This is it: HEXX: 436c564c49683441534373434245386c41784d6163464d5a5632686456566f74456868554a514e56416d685352776836515563496141773d orig: ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSRwh6QUcIaAw= base64 decoded: UK"H+O%pSWh]UZ-T%UhRGzAGh xor: 66.Lmo:Nf:sFf}i!|3Va6?Caw&@gk> 7){3"lV0 json_decode: out: Warning: array_values() expects parameter 1 to be an array or collection in /in/KEkNK on line 66 Type of based64:string Type of xored:string Type of json:NULL Type of out:NULL **** Hello World!