3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tmp = writeBookmark(17); //debug readBookmark($tmp); //debug // Bookmark Encode Function (one site) function writeBookmark($site) { $site = intval($site); $ts = timeStamp(); // calulates the size of the site id (posible options: 1,2,3,4) $site_id_size = strlen($site); // concatonate site id size, timestamp and site id $decoded_num = $site_id_size . $ts . $site; // Encode timestamp (Base 36) $encoded_num = fromDecimalToBase($decoded_num,36); return $encoded_num; //debug } // Bookmark Decode function function readBookmark($bookmark) { // Decode value $decoded_string = fromBaseToDecimal($bookmark, 36); echo $decoded_string . " "; if(!validateBookmark($decoded_string)) echo "Invalid Bookmark"; else if(is_link_expired($decoded_string) echo "Expired Link"; else { // sturf to link location $site_cnt = substr($decoded_string, 0,1); $site_id = substr($decoded_string, -($site_cnt),$site_cnt); $time_stamp = substr($decoded_string, 1,14); echo "site id cnt ". $site_cnt; echo "\ntime stamp ". $time_stamp; echo "\nsite id " . $site_id; // if valid, redirect to link // else redirect to invalide/expired link page }} /* Helper functions */// build timestamp ssmmhhddmmyyyy function timeStamp() { $ts = date('siHdmY'); return $ts;}// base convert (dec to base36)function fromDecimalToBase($in, $to) { $in = (string) $in; $out = ''; for ($i = strlen($in) - 1; $i >= 0; $i--) { $out = base_convert(bcmod($in, $to), 10, $to) . $out; $in = bcdiv($in, $to); } return preg_replace('/^0+/', '', $out);}// base convet (base36 to dec)function fromBaseToDecimal($in, $from) { $in = (string) $in; $out = ''; for ($i = 0, $l = strlen($in); $i < $l; $i++) { $x = base_convert(substr($in, $i, 1), $from, 10); $out = bcadd(bcmul($out, $from), $x); } return preg_replace('/^0+/', '', $out);}function validateBookmark($bm) { // numeric if(!is_numeric($bm)) { echo "nan"; return false; } // between 19 and 16 digits if(strlen($bm) > 19 || strlen($bm) < 16) { echo "outside range"; return false; } // first digit between 1 and 4 $locLength = substr($bm,0,1); if( $locLength <1 || $locLength >4) { echo "bad loc: ".$locLength; return false; } // if is passes all the tests return true return true;}function is_link_expired($ts) { $hou = substr($ts,5,2); $min = substr($ts,3,2); $sec = substr($ts,1,2); $day = substr($ts,7,2); $mon = substr($ts,9,2); $year = substr($ts,11,2); $bm_time = new DateTime($year."-".$mon."-".$day." ".$hou.":".$min.":".$sec); $current_time = new DateTime(); $difference = date_diff($bm_time,$current_time); }function validateURL($str){ return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i',$str);}function sanitize($str){ if(ini_get('magic_quotes_gpc')) $str = stripslashes($str); $str = strip_tags($str); $str = trim($str); $str = htmlspecialchars($str); $str = mysql_real_escape_string($str); return $str;}
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CP4KI
function name:  (null)
number of ops:  8
compiled vars:  !0 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL_BY_NAME                                       'writeBookmark'
          1        SEND_VAL_EX                                              17
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
    5     4        INIT_FCALL_BY_NAME                                       'readBookmark'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   23     7      > RETURN                                                   1

Function writebookmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CP4KI
function name:  writeBookmark
number of ops:  18
compiled vars:  !0 = $site, !1 = $ts, !2 = $site_id_size, !3 = $decoded_num, !4 = $encoded_num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        CAST                                          4  ~5      !0
          2        ASSIGN                                                   !0, ~5
   10     3        INIT_FCALL_BY_NAME                                       'timeStamp'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !1, $7
   12     6        STRLEN                                           ~9      !0
          7        ASSIGN                                                   !2, ~9
   14     8        CONCAT                                           ~11     !2, !1
          9        CONCAT                                           ~12     ~11, !0
         10        ASSIGN                                                   !3, ~12
   16    11        INIT_FCALL_BY_NAME                                       'fromDecimalToBase'
         12        SEND_VAR_EX                                              !3
         13        SEND_VAL_EX                                              36
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !4, $14
   18    16      > RETURN                                                   !4
   20    17*     > RETURN                                                   null

End of function writebookmark

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.44 ms | 1394 KiB | 13 Q