Redirect Based on Page Content
Scenario
Section titled “Scenario”You are promoting an offer with a network-wide daily cap. When the offer hits that cap, the network redirects to another offer you cannot promote, or do not want to promote.
You can send the visitor to an offer you choose when the network makes that switch.
How it works
Section titled “How it works”Place a PHP node before offer 1. The node fetches the offer page and looks for text that is only on that offer. If the text is there, the visitor goes to offer 1 on On Done 1. If it is not, the visitor goes to offer 2 on On Done 2.
The funnel looks like this:

Step 1: Add the custom tokens
Section titled “Step 1: Add the custom tokens”The page URL and the text to look for are set as custom tokens, so the same code works in other funnels and for other offers.
Open the funnel settings, expand Advanced settings and add these lines under Custom tokens:
content-checker-url=https://offer-page-urlcontent-checker-body=the page content to check for
Step 2: Add the PHP node
Section titled “Step 2: Add the PHP node”Use this code in the PHP node:
<?php
$url = '[[content-checker-url]]';$contentThatMustBeHere = '[[content-checker-body]]';$cacheSeconds = 300;
// Reuse a recent result so the page is not fetched for every visitor$cacheFile = sys_get_temp_dir() . '/ff-content-check-' . md5($url . $contentThatMustBeHere);if (is_file($cacheFile) && filemtime($cacheFile) > time() - $cacheSeconds) { return (int) file_get_contents($cacheFile);}
$ch = curl_init($url);curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 4,]);$output = curl_exec($ch);curl_close($ch);
if ($output === false) { // The check failed: keep sending visitors to offer 1 return 1;}
$route = (strpos($output, $contentThatMustBeHere) !== false) ? 1 : 2;file_put_contents($cacheFile, (string) $route, LOCK_EX);return $route;
?>The code does this:
- It reuses the last result for five minutes, so the offer page is fetched at most once every five minutes rather than for every visitor.
- It fetches the page with a four-second limit and follows the network’s redirects, as a visitor’s browser would.
- If the expected text is on the final page, it returns 1. Otherwise it returns 2.
- If the fetch fails, it returns 1, so a network problem does not move all your traffic.
The visitor waits while the page is fetched. Keep the timeouts short.
Dealing with geo-redirection
Section titled “Dealing with geo-redirection”Many networks geo-redirect visitors when they do not match the offer criteria. Your server’s location then decides which page the check sees, not the visitor’s.
Ask the affiliate network whether a parameter turns this off. Some links accept a preview or test parameter that goes straight to the offer page.
If there is no such parameter, send the check through a proxy or VPN server in the offer’s country.
Add cURL’s CURLOPT_PROXY option, with your provider’s proxy address, to the curl_setopt_array list.
Sending an email when the content changes
Section titled “Sending an email when the content changes”To get an email when the expected text is missing, add this before file_put_contents(...).
It sends one email each time the check result changes from 1 to 2, not one per visitor:
$previous = is_file($cacheFile) ? (int) file_get_contents($cacheFile) : 1;if ($route === 2 && $previous !== 2) { require_once 'PHPNodeHelpers.php';
PHPNodeHelpers::sendMail( [ 'to' => 'you@you.com', 'email-subject' => 'Offer content check failed', 'email-body' => 'The expected content is no longer on the offer page.', 'smtp-configuration' => [ 'server' => 'your-smtp.server.com', 'port' => 'port number', 'secure' => 'ssl', // this can be '', 'ssl' or 'tls' 'username' => 'username to smtp service', 'password' => 'password to smtp service', 'from-name' => 'Me', 'from-email' => 'me@me.com', ] ] );}See PHP node helper functions for the sendMail settings.

