Skip to content

Instantly share code, notes, and snippets.

@danmilleruk
Created August 28, 2013 20:30
Show Gist options
  • Save danmilleruk/6370834 to your computer and use it in GitHub Desktop.
Save danmilleruk/6370834 to your computer and use it in GitHub Desktop.
Convert amazon UK links to a referral tag.
<?PHP
$tag = "danmil-21";
if($_POST['submit'])
{
// Gather variables to store the submitted data and explode the values as needed
$url = $_POST['url'];
$array = explode("/", "$url");
$ASIN = $array[5];
if($array[4] != "product") {
echo "Invalid Amazon URL.<br><strong>MUST</strong> be in the following syntax (HTTP included): <u><strong>http://www.amazon.com/gp/product/B000PLY5BE</strong></u>ref=s9_simh_gw_p147_d0_i3";
} elseif (in_array("www.amazon.com", $array)) {
echo "Cannot use amazon.com links";
} else {
header("Location: http://www.amazon.co.uk/gp/product/{$ASIN}?ie=UTF8&tag={$tag}&camp=1634&creativeASIN={$ASIN}&linkCode=xm2");
}
}
?>
<h1>Generate Deehem's Amazon Affiliate URL</h1>
<form method="post" class="form-horizontal">
<input type="text" name="url">
<input type="submit" name="submit" value="Generate Amazon Link">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment