3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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>
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.2.6
<!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;"> <!-- 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="a1wr-12ac7a9eb51a" style="margin-bottom: 20px;"></div> <!-- this is the div containing the actual container, and where it will show on the page --> </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", "9780373622818"]); </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: '9780373622818', a1accesskeyid: '507WRLEEPZSZFCKGFPKYOZJ', expires: '1499283819', signature: 'EoO%2FDtGK1W9kZ%2FCVAhmOvNzozlQQWiBrX3o394%2F%2Fwoo%3D', containerCode: 'a1wr-12ac7a9eb51a', 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 EoO%2FDtGK1W9kZ%2FCVAhmOvNzozlQQWiBrX3o394%2F%2Fwoo%3D</h1> <h2> canonical is GET 1499283819 /recoservice/1.0/recommendations/target/9780373622818 containerCodes=a1wr-12ac7a9eb51a </h2> </body> </html>
Output for hhvm-3.15.4
<!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;"> <!-- 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="a1wr-12ac7a9eb51a" style="margin-bottom: 20px;"></div> <!-- this is the div containing the actual container, and where it will show on the page --> </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", "9780373622818"]); </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: '9780373622818', a1accesskeyid: '507WRLEEPZSZFCKGFPKYOZJ', expires: '1499283820', signature: '097YxWmKy6n3I3GEbNiQWPA%2BfaqsARCjwdLdwE3XrMQ%3D', containerCode: 'a1wr-12ac7a9eb51a', 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 097YxWmKy6n3I3GEbNiQWPA%2BfaqsARCjwdLdwE3XrMQ%3D</h1> <h2> canonical is GET 1499283820 /recoservice/1.0/recommendations/target/9780373622818 containerCodes=a1wr-12ac7a9eb51a </h2> </body> </html>