3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CRYPTO{ const TZ = 'UTC'; const TIMEFRAME = 100; const TIME = 'H:i:s'; public static function ver($data, $signature, $privateKey, $timestamp){ $now = self::timestamp(self::TZ); $tmin = ( $now - ( self::TIMEFRAME/2 ) ); $tmax = ( $now + ( self::TIMEFRAME/2 ) ); if( ($tmin>$tmax ) or ( $tmin<$tmax ) ) return false; //out of time range $data = strval( $data ); $computed_sig = self::signature($data, $privateKey, $timestamp); return $signature == $computed_sig; } public static function sign($data, $privateKey, $timestamp=null){ $timestamp = empty($timestamp) ? self::timestamp(self::TZ) : intval($timestamp); $data = strval( $data ); $sig = base64_encode( hash_hmac("sha256", $data, $privateKey . '-' . date(self::TIME, $timestamp), true) ); echo "Time: " . $timestamp; return $sig; } public static function timestamp($tz='GTM'){ $tz = new \DateTimeZone($tz); return date_create(NULL, $tz)->getTimestamp(); } public static function isValid($algo){ $algos = hash_algos(); return in_array($algo, $algos); } } date_default_timezone_set('UTC'); $timestamp = empty($timestamp) ? CRYPTO::timestamp(CRYPTO::TZ) : intval($timestamp); $success_url = "https://www.google.si/search?q=succesds"; $url = urlencode($success_url); echo " URL: " . $url; echo " Signature: " . CRYPTO::sign( $url, 'sddddddddddddddsa', $timestamp);
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: date_create(): Passing null to parameter #1 ($datetime) of type string is deprecated in /in/keCof on line 32 URL: https%3A%2F%2Fwww.google.si%2Fsearch%3Fq%3DsuccesdsTime: 1437754806 Signature: GzAjirRyWJ4T4cnvB/D84jn+VZSRobKkRiN6kT6N2KY=
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
URL: https%3A%2F%2Fwww.google.si%2Fsearch%3Fq%3DsuccesdsTime: 1437754806 Signature: GzAjirRyWJ4T4cnvB/D84jn+VZSRobKkRiN6kT6N2KY=

preferences:
219.56 ms | 403 KiB | 265 Q