-
-
Save bvbvbvbvbudw/42031bb9b76faf2a7b9b47dcfcece4e5 to your computer and use it in GitHub Desktop.
Cloaking.House redirect.php for multiple offers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // ========================================================================= | |
| // CONFIGURE ONLY THIS SECTION | |
| // ========================================================================= | |
| // Add as many offers as you need by copying a block | |
| // Weight is not a percentage - just a number for comparison | |
| // Example: 70 and 30 gives the same ratio as 7 and 3 | |
| // To temporarily disable an offer - set 'weight' => 0 | |
| $offers = [ | |
| [ | |
| 'url' => 'https://YOUR-LINK-A.com/', // Offer A | |
| 'weight' => 50 // % share of traffic | |
| ], | |
| [ | |
| 'url' => 'https://YOUR-LINK-B.com/', // Offer B | |
| 'weight' => 50 // % share of traffic | |
| ], | |
| // Uncomment to add a third offer: | |
| // [ | |
| // 'url' => 'https://YOUR-LINK-C.com/', | |
| // 'weight' => 50 // % share of traffic | |
| // ], | |
| ]; | |
| // ========================================================================= | |
| // DO NOT CHANGE ANYTHING BELOW | |
| // ========================================================================= | |
| $totalWeight = 0; | |
| foreach ($offers as $offer) { | |
| $totalWeight += $offer['weight']; | |
| } | |
| if ($totalWeight <= 0) { | |
| die("Error: weights not configured."); | |
| } | |
| $rand = mt_rand(1, $totalWeight); | |
| $sum = 0; | |
| $destinationUrl = ''; | |
| foreach ($offers as $offer) { | |
| $sum += $offer['weight']; | |
| if ($rand <= $sum) { | |
| $destinationUrl = $offer['url']; | |
| break; | |
| } | |
| } | |
| if (empty($destinationUrl)) { | |
| foreach ($offers as $offer) { | |
| if (!empty($offer['url'])) { | |
| $destinationUrl = $offer['url']; | |
| break; | |
| } | |
| } | |
| } | |
| if (empty($destinationUrl)) { | |
| die("Error: no valid URLs configured."); | |
| } | |
| if (!empty($_GET)) { | |
| $separator = (strpos($destinationUrl, '?') !== false) ? '&' : '?'; | |
| $destinationUrl .= $separator . http_build_query($_GET); | |
| } | |
| header("Location: " . $destinationUrl, true, 302); | |
| exit(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment