3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateSignature($path, $payload, $secret, $expires) { // Create the canonical string from expires and path $canonical = "GET\n\n\n" . $expires . "\n" . $path . ($payload != null ? "\n" . $payload : ""); // for example GET 1452204987 /recoservice/1.0/recommendations/target/122711000061 containerCodes=a1wr-162ed67911cc // Encrypt it with secret $signatureBytes = hash_hmac("sha256", $canonical, $secret, true); // Base64 encode the encrypted results and URL encode the base64 return urlencode(base64_encode($signatureBytes)); } function generatecanonical($path, $payload, $secret, $expires) { // Create the canonical string from expires and path $canonical = "GET\n\n\n" . $expires . "\n" . $path . ($payload != null ? "\n" . $payload : ""); // for example GET 1452204987 /recoservice/1.0/recommendations/target/122711000061 containerCodes=a1wr-162ed67911cc // Base64 encode the encrypted results and URL encode the base64 return $canonical; } $secret = "wbVx3n5/pgW0dTV/6nhW8QOVdr5HiWfZoXp1AcIJGfU="; //this is your secret API key that you can find in the Settings page $a1accesskeyid = "507WRLEEPZSZFCKGFPKYOZJ"; //this is your public API key that you can find in the Settings page $containerCodes = [ 'a1wr-12ac7a9eb51a' //put your container codes here. No need for an array if you have only one container on that page ]; $targetId = "9780373622818"; //this is an example, $targetId should contain the variable you use on your page for your Product ID $expires = time() + 900; //this makes API calls reusable for up to 15 min (900sec). You can make this longer or shorter, as you prefer (but not longer than 1h) $pathToAgilOne = "/recoservice/1.0/recommendations/target/" . $targetId; $payload = htmlentities('containerCodes=' . implode(',', $containerCodes)); $signature = generateSignature($pathToAgilOne, $payload, $secret, $expires); $canonical = generatecanonical($pathToAgilOne, $payload, $secret, $expires); ?> <!DOCTYPE html> <html> <head> <title>A1 Electronics</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <style> body { padding: 50px; font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; } a { color: #00B7FF; } </style> </head> <body style="padding: 0; margin: 0;"> <!-- Your page content --> <div style="padding: 20px; border-bottom: 1px solid #ccc; background: #E6F1F7"> <div style="float: right;"> <a href="" style="text-decoration: none;">My Account | Wish List | Order Status | My Shopping Cart</a> <div style="margin-top: 20px;">We take everything, except DISCOVER!</div> </div> <h1 style="padding: 0; margin: 0; color: #006699">A1 Electronics</h1> <span>If we don't have what you're looking for, it doesn't exist</span> </div> <!-- The div in which we will place the AgilOne container (it's actually not necessary to encapsulate it in a div) --> <div style="padding: 20px;"> <div style="margin-bottom: 30px; overflow: hidden; width: 800px;"> <?php foreach ($containerCodes as $containerCode) { ?> <!-- note that this "for" loop isn't relevant for your website. You should put each div in the proper location for your website --> <div id="<?= $containerCode ?>" style="margin-bottom: 20px;"></div> <!-- this is the div containing the actual container, and where it will show on the page --> <?php } ?> </div> </div> <!-- This part below is for the AgilOne Webtag. Don't re-implement it if you already have it on your page. --> <script type='text/javascript'> var _a1as = _a1as || []; _a1as.push(["init","1234567"]); _a1as.push(["track"]); _a1as.push(["product_view", "<?= $targetId ?>"]); </script> <script type='text/javascript'> (function() { var a1s = document.createElement('script'); a1s.type = 'text/javascript'; a1s.async = true; a1s.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'tr-1.agilone.com/tr-as.js'; var a1ss = document.getElementsByTagName('script')[0]; a1ss.parentNode.insertBefore(a1s, a1ss); })(); </script> <!-- End of the AgilOne Webtag script --> <!-- This is the script for the AgilOne Web container --> <script type='text/javascript'> var _a1wr = { target: '<?php echo $targetId ?>', a1accesskeyid: '<?php echo $a1accesskeyid ?>', expires: '<?php echo $expires ?>', signature: '<?php echo $signature ?>', containerCode: '<?php echo implode(',', $containerCodes) ?>', apiHost: 'awrs.agilone.com', apiPort: window.location.protocol === 'http:' ? '8080' : '8443', _debug: true }; </script> <script src="//awrs.agilone.com/static/a1wr.min.js"></script> <!-- End of AgilOne Web container script --> <h1>signature is <?php echo $signature ?></h1> <h2> canonical is <?php echo $canonical ?> </h2> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/EPTHZ
function name:  (null)
number of ops:  63
compiled vars:  !0 = $secret, !1 = $a1accesskeyid, !2 = $containerCodes, !3 = $targetId, !4 = $expires, !5 = $pathToAgilOne, !6 = $payload, !7 = $signature, !8 = $canonical, !9 = $containerCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, 'wbVx3n5%2FpgW0dTV%2F6nhW8QOVdr5HiWfZoXp1AcIJGfU%3D'
   28     1        ASSIGN                                                   !1, '507WRLEEPZSZFCKGFPKYOZJ'
   29     2        ASSIGN                                                   !2, <array>
   32     3        ASSIGN                                                   !3, '9780373622818'
   33     4        INIT_FCALL                                               'time'
          5        DO_ICALL                                         $14     
          6        ADD                                              ~15     $14, 900
          7        ASSIGN                                                   !4, ~15
   34     8        CONCAT                                           ~17     '%2Frecoservice%2F1.0%2Frecommendations%2Ftarget%2F', !3
          9        ASSIGN                                                   !5, ~17
   35    10        INIT_FCALL                                               'htmlentities'
         11        INIT_FCALL                                               'implode'
         12        SEND_VAL                                                 '%2C'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $19     
         15        CONCAT                                           ~20     'containerCodes%3D', $19
         16        SEND_VAL                                                 ~20
         17        DO_ICALL                                         $21     
         18        ASSIGN                                                   !6, $21
   36    19        INIT_FCALL                                               'generatesignature'
         20        SEND_VAR                                                 !5
         21        SEND_VAR                                                 !6
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !4
         24        DO_FCALL                                      0  $23     
         25        ASSIGN                                                   !7, $23
   37    26        INIT_FCALL                                               'generatecanonical'
         27        SEND_VAR                                                 !5
         28        SEND_VAR                                                 !6
         29        SEND_VAR                                                 !0
         30        SEND_VAR                                                 !4
         31        DO_FCALL                                      0  $25     
         32        ASSIGN                                                   !8, $25
   40    33        ECHO                                                     '%0A%0A%3C%21DOCTYPE+html%3E%0A%3Chtml%3E%0A%0A++%3Chead%3E%0A++++%3Ctitle%3EA1+Electronics%3C%2Ftitle%3E%0A++++%3Cscript+src%3D%22%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F2.1.1%2Fjquery.min.js%22%3E%3C%2Fscript%3E%0A++++%3Cstyle%3E%0A++++++++body+%7B%0A++++++++++padding%3A+50px%3B%0A++++++++++font%3A+14px+%22Lucida+Grande%22%2C+Helvetica%2C+Arial%2C+sans-serif%3B%0A++++++++%7D%0A++++++++a+%7B%0A++++++++++color%3A+%2300B7FF%3B%0A++++++++%7D%0A++++%3C%2Fstyle%3E%0A++%3C%2Fhead%3E%0A%0A++%3Cbody+style%3D%22padding%3A+0%3B+margin%3A+0%3B%22%3E%0A++++%3C%21--+Your+page+content+--%3E%0A++++%3Cdiv+style%3D%22padding%3A+20px%3B+border-bottom%3A+1px+solid+%23ccc%3B+background%3A+%23E6F1F7%22%3E%0A++++++++%3Cdiv+style%3D%22float%3A+right%3B%22%3E%0A++++++++++++%3Ca+href%3D%22%22+style%3D%22text-decoration%3A+none%3B%22%3EMy+Account+%7C+Wish+List+%7C+Order+Status+%7C+My+Shopping+Cart%3C%2Fa%3E%0A++++++++++++%3Cdiv+style%3D%22margin-top%3A+20px%3B%22%3EWe+take+everything%2C+except+DISCOVER%21%3C%2Fdiv%3E%0A++++++++%3C%2Fdiv%3E%0A++++++++%3Ch1+style%3D%22padding%3A+0%3B+margin%3A+0%3B+color%3A+%23006699%22%3EA1+Electronics%3C%2Fh1%3E%0A++++++++%3Cspan%3EIf+we+don%27t+have+what+you%27re+looking+for%2C+it+doesn%27t+exist%3C%2Fspan%3E%0A++++%3C%2Fdiv%3E%0A%0A++++%3C%21--+The+div+in+which+we+will+place+the+AgilOne+container+%28it%27s+actually+not+necessary+to+encapsulate+it+in+a+div%29+--%3E%0A++++%3Cdiv+style%3D%22padding%3A+20px%3B%22%3E%0A++++++++%3Cdiv+style%3D%22margin-bottom%3A+30px%3B+overflow%3A+hidden%3B+width%3A+800px%3B%22%3E%0A++++++++++++'
   73    34      > FE_RESET_R                                       $27     !2, ->40
         35    > > FE_FETCH_R                                               $27, !9, ->40
   74    36    >   ECHO                                                     '++++++++++++++++%3C%21--+note+that+this+%22for%22+loop+isn%27t+relevant+for+your+website.+You+should+put+each+div+in+the+proper+location+for+your+website+--%3E%0A++++++++++++++++%3Cdiv+id%3D%22'
   75    37        ECHO                                                     !9
         38        ECHO                                                     '%22+style%3D%22margin-bottom%3A+20px%3B%22%3E%3C%2Fdiv%3E+%3C%21--+this+is+the+div+containing+the+actual+container%2C+and+where+it+will+show+on+the+page+--%3E%0A++++++++++++'
   73    39      > JMP                                                      ->35
         40    >   FE_FREE                                                  $27
   77    41        ECHO                                                     '++++++++%3C%2Fdiv%3E%0A++++%3C%2Fdiv%3E%0A%0A++++%3C%21--+This+part+below+is+for+the+AgilOne+Webtag.+Don%27t+re-implement+it+if+you+already+have+it+on+your+page.+--%3E%0A++++%3Cscript+type%3D%27text%2Fjavascript%27%3E%0A++++++++var+_a1as+%3D+_a1as+%7C%7C+%5B%5D%3B%0A++++++++_a1as.push%28%5B%22init%22%2C%221234567%22%5D%29%3B%0A++++++++_a1as.push%28%5B%22track%22%5D%29%3B%0A++++++++_a1as.push%28%5B%22product_view%22%2C+%22'
   85    42        ECHO                                                     !3
         43        ECHO                                                     '%22%5D%29%3B%0A++++%3C%2Fscript%3E%0A++++%3Cscript+type%3D%27text%2Fjavascript%27%3E%0A++++++++%28function%28%29+%7B%0A++++++++++++var+a1s+%3D+document.createElement%28%27script%27%29%3B%0A++++++++++++a1s.type+%3D+%27text%2Fjavascript%27%3B%0A++++++++++++a1s.async+%3D+true%3B%0A++++++++++++a1s.src+%3D+%28%27https%3A%27+%3D%3D+document.location.protocol+%3F+%27https%3A%2F%2F%27+%3A+%27http%3A%2F%2F%27%29+%2B+%27tr-1.agilone.com%2Ftr-as.js%27%3B%0A++++++++++++var+a1ss+%3D+document.getElementsByTagName%28%27script%27%29%5B0%5D%3B%0A++++++++++++a1ss.parentNode.insertBefore%28a1s%2C+a1ss%29%3B%0A++++++++%7D%29%28%29%3B%0A++++%3C%2Fscript%3E%0A++++%3C%21--+End+of+the+AgilOne+Webtag+script+--%3E%0A%0A++++%3C%21--+This+is+the+script+for+the+AgilOne+Web+container+--%3E%0A++++%3Cscript+type%3D%27text%2Fjavascript%27%3E%0A++++++++var+_a1wr+%3D+%7B%0A++++++++++++target%3A+%27'
  102    44        ECHO                                                     !3
         45        ECHO                                                     '%27%2C%0A++++++++++++a1accesskeyid%3A+%27'
  103    46        ECHO                                                     !1
         47        ECHO                                                     '%27%2C%0A++++++++++++expires%3A+%27'
  104    48        ECHO                                                     !4
         49        ECHO                                                     '%27%2C%0A++++++++++++signature%3A+%27'
  105    50        ECHO                                                     !7
         51        ECHO                                                     '%27%2C%0A++++++++++++containerCode%3A+%27'
  106    52        INIT_FCALL                                               'implode'
         53        SEND_VAL                                                 '%2C'
         54        SEND_VAR                                                 !2
         55        DO_ICALL                                         $28     
         56        ECHO                                                     $28
         57        ECHO                                                     '%27%2C%0A++++++++++++apiHost%3A+%27awrs.agilone.com%27%2C%0A++++++++++++apiPort%3A+window.location.protocol+%3D%3D%3D+%27http%3A%27+%3F+%278080%27+%3A+%278443%27%2C%0A++++++++++++_debug%3A+true%0A%09%09%0A++++++++%7D%3B%0A++++%3C%2Fscript%3E%0A++++%3Cscript+src%3D%22%2F%2Fawrs.agilone.com%2Fstatic%2Fa1wr.min.js%22%3E%3C%2Fscript%3E%0A++++%3C%21--+End+of+AgilOne+Web+container+script+--%3E%0A%09++%3Ch1%3Esignature+is+'
  115    58        ECHO                                                     !7
         59        ECHO                                                     '%3C%2Fh1%3E%0A%09++%3Ch2%3E%0A%09%09++canonical+is+'
  117    60        ECHO                                                     !8
  118    61        ECHO                                                     '%09++%3C%2Fh2%3E%0A%09%0A%09++%0A++%3C%2Fbody%3E%0A%0A%3C%2Fhtml%3E'
  123    62      > RETURN                                                   1

Function generatesignature:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EPTHZ
function name:  generateSignature
number of ops:  30
compiled vars:  !0 = $path, !1 = $payload, !2 = $secret, !3 = $expires, !4 = $canonical, !5 = $signatureBytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    4     4        CONCAT                                           ~6      'GET%0A%0A%0A', !3
          5        CONCAT                                           ~7      ~6, '%0A'
          6        CONCAT                                           ~8      ~7, !0
          7        IS_NOT_EQUAL                                             !1, null
          8      > JMPZ                                                     ~9, ->12
          9    >   CONCAT                                           ~10     '%0A', !1
         10        QM_ASSIGN                                        ~11     ~10
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~11     ''
         13    >   CONCAT                                           ~12     ~8, ~11
         14        ASSIGN                                                   !4, ~12
    9    15        INIT_FCALL                                               'hash_hmac'
         16        SEND_VAL                                                 'sha256'
         17        SEND_VAR                                                 !4
         18        SEND_VAR                                                 !2
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !5, $14
   12    22        INIT_FCALL                                               'urlencode'
         23        INIT_FCALL                                               'base64_encode'
         24        SEND_VAR                                                 !5
         25        DO_ICALL                                         $16     
         26        SEND_VAR                                                 $16
         27        DO_ICALL                                         $17     
         28      > RETURN                                                   $17
   13    29*     > RETURN                                                   null

End of function generatesignature

Function generatecanonical:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EPTHZ
function name:  generatecanonical
number of ops:  17
compiled vars:  !0 = $path, !1 = $payload, !2 = $secret, !3 = $expires, !4 = $canonical
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   17     4        CONCAT                                           ~5      'GET%0A%0A%0A', !3
          5        CONCAT                                           ~6      ~5, '%0A'
          6        CONCAT                                           ~7      ~6, !0
          7        IS_NOT_EQUAL                                             !1, null
          8      > JMPZ                                                     ~8, ->12
          9    >   CONCAT                                           ~9      '%0A', !1
         10        QM_ASSIGN                                        ~10     ~9
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~10     ''
         13    >   CONCAT                                           ~11     ~7, ~10
         14        ASSIGN                                                   !4, ~11
   22    15      > RETURN                                                   !4
   23    16*     > RETURN                                                   null

End of function generatecanonical

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.83 ms | 1411 KiB | 27 Q