Skip to content

How To make a Script to check your Affiliate Landing Page is UP!!!!

It’s midnight on Tuesday and all of a sudden the offer you were promoting isn’t working anymore!

Have you ever had this happen to you? There’s nothing worse then paying for clicks that aren’t going anywhere. Especially if those are 2-3$ clicks for a niche like mortgage or payday loans. You call your affiliate manager the next day, or even worse don’t notice for a few days, and ask them “hey what happened to xyz campaign?” Do you know what the words out of their mouth are always? “Oh I sent you an email…” but some how it ended up in your spam box or you didn’t pay attention as you get lots of emails from all the affiliate companies every day.

Now what if you had a way to make sure your offers were working and you had control rather then waiting for someone else to alert you? In this example we’re going to make it so that the alert comes to your email but of course this could be adapted to instant messenger, a text message, or any other communication device with a little finessing.

In all these tutorials I’m going to assume you’ve at least coverered the intial tutorials on on how to do some scraping and parsing of data. If you haven’t please go read the php screen scraping and parsing tutorials.

First step in solving this problem is we need to make a simple script that will go request the affiliate’s landing page you’re promoting. To do that we’ll just use the file_get_contents() function which we know is going to go grab the data from a file or website based on a string we put into the parameters. Then we’re going to assign that to a variable or holder called $page. If you don’t know a $ always indicates a variable. Then lastly we’ll echo the contents that we reach out and grabbed using the echo statement which just echo’s what is in the variable $page to the screen. Here’s what your code should look like.


$page = file_get_contents(“”);
echo $page;


I invite you to make a little text file on your server and called: offer_check.php and putting the lines of code above in it. Of course you’re going to want to replace your destination url with an actual url of your affiliate company. However now comes the bad news. As most offers bounce through a redirect url this simple file_get_contents() function isn’t going to work for most things. However I just wanted to start with it. Now we’re going to a little more robust library and start to use curl. So if we were to do that exact same thing again but this time using curl it would look like this.


$ch = curl_init( “” );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
echo $page;


Most of this is fairly intuitive however there’s a couple of things I’d like touch on. With the Curl library we have the option of setting different things we want to do where the file_get_contents() is only going to request a single page. So if they link goes to Copeac then bounces to the affilliate landing page nothing is going to be returned by file_get_contents() because it will only get the first redirect page. Now we could manually parse and follow each redirect however it’s much simpler to just use Curl who’ll follow the redirects automatically for us if we set the right options.

As you probably guessed the easiest way you set a url in Curl is in the initialization statement. Then we’re assigning that initialized object to the variable $ch. However we haven’t done anything with it yet, this hasn’t requested the page. This just made a container to set some options in. To set those options I’m sure you saw the function curl_setopt() basically it takes arguments of the object/variable holding the contatiner, $ch in this case, to set options on. The second parameter is the option we want to set. We’re setting 2 in this example:

  • CURLOPT_FOLLOWLOCATION – Follows redirects automatically
  • CURLOPT_RETURNTRANSFER – Returns the page output to a variable

So in a nutshell we’re initalizing a container and setting the variable for the url inside that container to the url of our affilaite program. Then we’re telling Curl to automatically follow all redirects to the final destination. Next we say hey don’t just do this but return the page to me so I can do some stuff with it. Curl_exec() pulls does the actual work based on all the options we’ve set in the container and returns that data to the var $page.

Now as long as Curl is enabled on your server or where ever you run your PHP scripts you’re going to get the actual page affilaite page back even if there’s a redirect. I strongly encourage you to take this code and put it on your server and run it. Make sure it works before we go on to the next step.

Now that we have our offer page in the variable $page and we need to find someway to check whether it is up or not. Being that we have the actual source code of the page lets look for something we could check for. For this example we’ll go back to using the homepage of Now direct your browser to After taking a look around I decided the thing most likely to change is the title of the page. So I grabbed the words “PHP Scraping Tutorials” and decided if those didn’t show up then there was something wrong with the landing page. The checking script is going to look like this.


$url = “” ;
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);

if(strchr($page,”PHP Scraping Tutorials”)){
echo “still works!”;
mail(“[email protected]”,”Offer is down”,”The offer $url is down.”);


The quick and dirty on the second part is it’s saying if this to this, if not this then do something else. What we’re doing is in our if statement we’re using the function strchr() which returns a number for the first position of our string. Guess what happens if there’s no match? That’s right it returns null. In which case the initial if() isn’t true so it moves on to the else. At which time the script emails you to the email you enter, with the subject “Offer is down” and then body “The offer is down.” Now you can manually go check if this is working or not. And if not pause your campaigns until it comes back up or you can talk to an affiliate manager.

The last part of this is to set it to run on a cron or timer automatically. In linux as that’s the OS i use you set a cron using >crontab -e where the -e is for edit. I suggest running this every 10 minutes so you’ll want to enter a line that reads:

*/10 * * * * /home/username/scripts/offer_check.php

Now of course this location is going to be for where ever your script is located on your server. What this will do is run the script and check whether your offers are up ever 10 minutes. And email you if your offers are down.

One quick addition to make this simpler to manage would be to add a second text file to hold the list of offers and matching strings. It would look something like this:

offers.txt,text to check,more text to check


$lines = file(“offers.txt”);
foreach($lines as $line){

$parts = explode(“,”,$line);

$url = trim($parts[0]);
$search_string = trim($parts[1]);

$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);

echo “still works!<br />”;
mail(“[email protected]”,”Offer is down”,”The offer $url is down.”);



( If you take this code and copy it the double quotes do something funny. Make sure you replace them with real double quotes. )

Quickly this takes the lines from a file and loads them into an array. After that it loops through each of the lines in the array. Then splits those array’s based on a comma as that’s the format we used for our file. At which time it tests all the conditions just like we did for the single one.

I hope this tutorial helps you save some money in affiliate marketing with offers that have been canceled that you don’t know about. This way you can pause or redirect your google adwords campaigns, CPM buys or where ever else your traffic comes from.

Did you get some good information from this Post? If you did, would you do me a favor and link to it?


  1. this is a great script, thanks smaxor!
    there is a missing ) in it though for people that copy it word for word…also wordpress has made all of the quotation marks be in italics.
    here is a working version i just tested:

    mail(“[email protected]”,”Offer is down”,”The offer $url is down.”);


  2. I actually updated it in the code on the page as well. πŸ™‚

  3. Roman Roman

    Thank you. This script is actual, because its really a problem with dead offers.

  4. Sure no worries, Happy to help.

  5. Smilz Smilz

    Great stuff big guy. Will be playing with this over the weekend. I have needed something like this for a while.

  6. Denis Denis

    Great script …

    I found this on google, but it is not exactly what I am looking for.
    I have been looking for the past 2 weeks for a solution but had no sucess as of yet. I am hoping someone can help πŸ™

    Here is what I am trying to accomplish:

    I am looking for some kind of script, apps, or any kind or solution that will let me have a complete archive of all of may domain names and basically redirect each one to either my server, parking program or affiliate pages.

    I know there are certain scripts out there with a control panel to organize /redirect domains but I want to take my domains one step further and have some of them redirect only on a hour, day, week, month schedule.

    This step is very important since some of my domains perform better at certain times of the day, week and/or month.

    Is there anything out there that can do this?

  7. Sure that would be to hard I’ll see if I can write up a post for you today. So just to clarify you’re looking for something that you can have X number of domains and they redirect to certain places at certain times?

    What would be the easiest is have them as virtually hosted on your server. Then you could make 1 catch-all for all the domains that didn’t have records. That catch-all would redirect all your domains to the same index.php file. Which would read the domain using the $_SERVER values. Then would lookup where to send that domain based on timeframe. You could make it track traffic as well since you’re in a php file.

    So to make this setup up work once it was setup all you have to do is point the DNS record to the server and you’re all set. In namecheap you can just add the IP and A RECORD or whatever it’s called. I do that a lot with domains. Just buy 100 and then set them all to go to a server and deal with them when they get there.

  8. Denis Denis

    Yes exactly.

    I have over 400 and it is unrealistic for me to go thru them every day and change the DNS / Forwarding individually for each domain. To make things more complex, some of the domains need to be left pointed to an actual developed affiliate website BUT at certain times of the day have the same domain redirect to a parked page for a certain amount of time and finally redirect again to the initial developed website. The reason for this is because I found that certain domains perform better at certain times of the day parked and better at my developed website on certain times of the day.

    I also need to be able to manage all my domains from one location since there are lots of them … it would be cutting time dramatically.

    I am very new to Crons, PHP, Scripts, etc … so you might have to describe everything in layman’s term πŸ˜‰

    P.S. Would love to have you write up a new post on this. I’m sure there are tons of other people looking for the same solution.

    Thanks for your help so far!

  9. Julian Julian

    anybody know of a script i could install to with a admin interface to maintain multiple domains like this?

  10. Hi Julian,

    Can you be little more specific? Do you want an interface that you log into and it then checks if they’re up? Or how do you mean interface that controls multiple domains.


  11. Rob Rob


    Doesn’t seem to work with neverblue jumplinks, maybe they’re redirecting multiple times?

  12. Thanks, nice script!
    I’ll implement a tweaked version of this. πŸ™‚

Comments are closed.