This is a simple PHP script to quickly generate a concise Amazon affiliate link. Just take any Amazon product page link or product ID, paste it in the big box, and hit submit. A working demo is shown below, and the source code is published further down the page.
Demo:
Source:
<html> <head> <style> body { margin: 0; } #wrapper { max-width: 600px; margin: 10 auto; } #azform { padding: 0 10px; } #azlink { width: 100%; } #azlinkgen { text-align: center; margin: 15 auto 0 auto; } #genlinks { padding: 10px; border-top: 1px dotted black; text-align: center; } </style> </head> <body> <div id="wrapper"> <div id="azform"> <form action="<?php echo basename(__FILE__); ?>"> <p>Affiliate ID: <input type="text" name="azaffiliate" value="walsranfes08-20"></p> <p>Amazon Product Link or ID: <input id="azlink" type="text" name="azlink" value="<?php if (isset($_GET["azlink"])) { $azlink = $_GET["azlink"]; echo $azlink; } ?>"></p> <div id="azlinkgen"><input type="submit" value="Submit"></div> </form> </div> <?php if ($azlink) { if (strlen($azlink) == 10) { $productid = $azlink; } else { preg_match("/\/([a-zA-Z0-9]{10})(\/|$)/", $azlink, $parsetest); $productid = $parsetest[1]; } if (strlen($productid) == 10 && ctype_alnum($productid)) { $afflink = "http://www.amazon.com/dp/" . $productid . "/?tag=" . $_GET["azaffiliate"]; echo "<div id=\"genlinks\"><a href=" . $afflink . ">" . $afflink . "</a><br>or<br>"; $afflink = "http://www.amazon.com/exec/obidos/ASIN/" . $productid . "/" . $_GET["azaffiliate"] . "/"; echo "<a href=" . $afflink . ">" . $afflink . "</a></div>"; } else { echo "There was an error parsing the input."; } } ?> </div> </body> </html>