Ich Referenz gelegentlich Produkte auf meine verschiedenen Websites, und in der Regel, sie zu Amazon Link für jedermann interessiert an dem Kauf. Vor langer Zeit habe ich mit einem Amazon Partner Link Link aber verdienen nie etwas von ihm als meine typischen Leserschaft gut auf der ganzen Welt verteilt ist. Leider Amazon bieten keinen Weg, um Besucher auf ihre lokale amazon Site zu umleiten unter Beibehaltung an verbundenen Unternehmen Zahlungen. Es gibt verschiedene Lösungen gibt, aber alle diejenigen, fand ich hatte Probleme mit ihnen, also habe ich mein eigenes entwickelt.
Ich könnte es zu einem Plugin zur Veröffentlichung entwickeln, wenn genügend Nachfrage besteht. In der Zwischenzeit, der Code ist unten. Sie müssen einige Änderungen vornehmen, damit sie mit Ihrer Site-Adresse und Ihren Amazon-Partnercodes übereinstimmt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | <?php /** * Plugin Name: Amazon Affiliates Redirect * Plugin URI: https://diymediahome.org/ * Description: Redirects all amazon affiliates links to a local amazon store depending on visitors location. * Version: 1.0 * Author: Jon P Scaife * Author URI: https://jonscaife.com * License: GPL12 */ function process_link() { $debug=false; //Detect visitor location from IP if (isset($_SERVER[‘HTTP_CLIENT_IP’])) { $real_ip_address = $_SERVER[‘HTTP_CLIENT_IP’]; } if (isset($_SERVER[‘HTTP_X_FORWARDED_FOR’])) { $real_ip_address = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; } else { $real_ip_address = $_SERVER[‘REMOTE_ADDR’]; } function curl_get_contents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } $iptolocation = ‘http://ip-api.com/php/’ . $real_ip_address; $ipreply = @unserialize(curl_get_contents($iptolocation)); $iplocation = $ipreply[‘countryCode’]; //Detect visitor language from browser $browserlang= substr($_SERVER[‘HTTP_ACCEPT_LANGUAGE’], 0, 2); //Detect language of page visitor is using if (isset($_GET[‘lang’])) { $userlang= $_GET[‘lang’]; } else { $userlang= “EN”; } //was a link passed if (isset($_GET[‘addr’])) { $original_link= $_GET[‘addr’]; } //Decide best amazon site based on data detected $linkpartone= $_GET[‘creativeASIN’]; switch ($iplocation) { case ‘GB’: $link=“https://www.amazon.co.uk/dp/”.$linkpartone.“/ref=nosim?tag=dimeho-21”; break; case ‘IE’: $link=“https://www.amazon.co.uk/dp/”.$linkpartone.“/ref=nosim?tag=dimeho-21”; break; case ‘US’: $link=“https://www.amazon.com/dp/”.$linkpartone.“/ref=nosim?tag=jonstech-20”; break; case ‘CA’: $link=“https://www.amazon.ca/dp/”.$linkpartone.“/ref=nosim?tag=dimeho-20”; break; case ‘CN’: $link=“https://www.amazon.cn/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘HK’: $link=“https://www.amazon.cn/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘MO’: $link=“https://www.amazon.cn/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘IN’: $link=“https://www.amazon.in/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘JP’: $link=“https://www.amazon.co.jp/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘FR’: $link=“https://www.amazon.fr/dp/”.$linkpartone.“/ref=nosim?tag=Dimeho02-21”; break; case ‘CH’: $link=“https://www.amazon.fr/dp/”.$linkpartone.“/ref=nosim?tag=Dimeho02-21”; break; case ‘BE’: $link=“https://www.amazon.fr/dp/”.$linkpartone.“/ref=nosim?tag=Dimeho02-21”; break; case ‘MC’: $link=“https://www.amazon.fr/dp/”.$linkpartone.“/ref=nosim?tag=Dimeho02-21”; break; case ‘LU’: $link=“https://www.amazon.fr/dp/”.$linkpartone.“/ref=nosim?tag=Dimeho02-21”; break; case ‘DE’: $link=“https://www.amazon.de/dp/”.$linkpartone.“/ref=nosim?tag=dimeho0f-21”; break; case ‘CZ’: $link=“https://www.amazon.de/dp/”.$linkpartone.“/ref=nosim?tag=dimeho0f-21”; break; case ‘IT’: $link=“https://www.amazon.it/dp/”.$linkpartone.“/ref=nosim?tag=diymediahome-21”; break; case ‘NL’: $link=“https://www.amazon.nl/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘ES’: $link=“https://www.amazon.es/dp/”.$linkpartone.“/ref=nosim?tag=diymediahom05-21”; break; case ‘MX’: $link=“https://www.amazon.com.mx/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘AU’: $link=“https://www.amazon.com.au/dp/”.$linkpartone.”/ref=nosim?tag=”; break; case ‘BR’: $link=“https://www.amazon.com.br/dp/”.$linkpartone.”/ref=nosim?tag=”; break; default: $link=“https://www.amazon.com/dp/”.$linkpartone.“/ref=nosim?tag=jonstech-20”; } if($debug==true) { echo “1. $iplocation. 2. $browserlang. 3. $userlang. 4. $link”; } else { header(‘Location: ‘.$link); die(); } } if (isset($_GET[‘addr’])) process_link(); //create filter to replace amazon links with internal redirect inc a random code to prevent caching function modify_amazon_affiliate_links($content) { $content= str_replace(‘<a rel=“nofollow” href=“https://www.amazon’, ‘<script>var ran_var= Math.random();</script><a style=“background: none;” rel=“nofollow” onclick=“location.href=this.href+\’?ran=\’+ran_var;return false;” target=“_blank” href=“https://jonscaife.com/wp-content/plugins/amazon-affiliates-redirect.php?addr=’, $content); return str_replace(‘<a href=“https://www.amazon’, ‘<script>var ran_var= Math.random();</script><a style=“background: none;” rel=“nofollow” onclick=“location.href=this.href+\’?ran=\’+ran_var;return false;” target=“_blank” href=“https://jonscaife.com/wp-content/plugins/amazon-affiliates-redirect.php?addr=’, $content); } add_filter( ‘the_content’, ‘modify_amazon_affiliate_links’ ) ?> |
Hinweis – der Code ist derzeit ein früher Entwurf. Es klappt, aber es nutzt nicht einige der Erkennungsmerkmale, die es tun kann. Es hat keine Einstellungsseite für die Associate-IDs, und es verwendet eine hartcodierte Site-Adresse, statt einer unsichtbaren Weiterleitung. Es verwendet jedoch clientseitiges Javascript, um jedes Mal eine eindeutige Umleitungs-URL zu generieren, um zu verhindern, dass Caching-Systeme eine falsche Standorterkennung verursachen.
Haben Sie ein paar Gedanken des eigenen? Lassen Sie sich unten durch die Kommentierung! Wenn Sie bitte abonnieren möchten den Link oben rechts auf dem Menü abonnieren verwenden. Sie können auch unten unter Verwendung der sozialen Bindungen diese mit Ihren Freunden teilen. Prost.
Hinterlasse eine Antwort