Easy “PHP Proxy Checker” Writing Tutorial

I started to write this on Eli’s forum but decided to add it here so everyone could reference it.

If you have a list of proxies that you’ve got from somewhere and want to verify if they’re good or not this is simple script that will read a text file and check them.

First we’ll make a text file with our proxies on each line of the file in the format IP:PORT with one per line.

127.127.127.127:2487
123.123.123.123:3248

then save that text file as “proxylist.txt” in the same directory as the php file you’re going to make. Then we’ll start our php file with our proxy checking in it. Here’s the complete script that just echo’s the status of each proxy out to the screen. We’ll make a few changes and have it write a new file with only the good proxies next.

// This is the page that that we're going to request going through the proxy
$testpage = "http://www.google.com";
// This loads all the proxies from the file into an array
$proxies = file("proxylist.txt");
// Here we loop through each cell of the array with the proxies in them testing each one until we get to the end of the array
foreach($proxies as $proxy)
{
// This script utilizes cURL which is library you can read more about
//using curl in my intro tutorials
// starting curl and setting the page to get
$ch = curl_init($testpage);
// sets the proxy to go through
curl_setopt($ch,CURLOPT_PROXY,$proxy);
// sets to use a tunnel proxy which most http proxies are
curl_setopt($ch,CURLOPT_HTTPTUNNELPROXY,$proxy);
// makes the curl call do it's work based on what we've set previously and
//returns that fetched page to $page
$page = curl_exec($ch);
// cleans up the curl set
curl_close($ch);
// this will check that there was some html returned, now some sites might block some
//proxies so you'd want to set for that specific site in the $testpage var and then
//find something on that page to look for with the below function.
$check = stripos($page,'</html>');
// if there was a match in the stripos (string postion) function echo that the
//proxy got the data and works
if($check > 0)
{
echo $proxy." Works!
";
// or else echo it doesn't work
}else{
echo $proxy." Is Dead!
";
}
}
?>

There’s your code. The gist of this is that we load each line from a file into an array. Then we loop through each array element checking if we can get the google page going through the proxy. Then if it pulls data it prints on the screen that the proxy works or if it doesn’t get something returned it doesn’t.

Now we might not want to print things to the screen and would rather make a new file with the the good proxies. To do that we’d swap this code:

if($check > 0)

{

 echo $proxy." Works!";

// or else echo it doesn't work

}else{

 echo $proxy." Is Dead!";

}

with:

if($check > 0){file_put_content("newproxylist.txt",$proxy."n",FILE_APPEND);}

rename('proxylist.txt','proxylistold.txt)';

rename('newproxylist.txt','proxylist.txt');

}

And that will write a new file and add each of the good proxies to it. Then rename the the original file to proxylistold.txt in case there was an error it’s good to have a backup. Then we rename the newpoxylist.txt to the standard proxylist.txt and it’s all fresh and ready to go. There you have it a nice simple proxy checker.

P.S. make sure you make the dir that they’re in writable as there’ll be issues with creating a new file in an unwritable dir.

P.P.S Trying this new code plug-in and well let me tell yah. IT’S A HUGE PAIN IN THE ASS!

Domainer Time Based Redirect PHP script – Part 1

As most of you know I’m no domainer. I think I own a grand total of 100 domains or less. However one of our readers is and asked for an easy script to redirect their domains in a time based fashion. He mentioned that after tracking his domains he finds that sometimes redirecting the traffic to a parked page makes him more money for those times then it would redirecting it to an affiliate offer.

Denis:
“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.”

You can read the comments where the conversation stemmed from here here.

The Domainer Time Based Redirect Project

For this project we have a few goals

  1. Make domains point to the same server.
  2. Have that server forward all domains that it doesn’t recognize to the same file to be process and controlled by that file.
  3. Design some sort of data structure to hold the incoming domains and where they should be forwarded to
  4. Build a file that will look for that domain in a database and then verify against what time it is to determine where it should send the traffic to.

Sounds fairly simple but it’ll be a bit complicated. That’s why I’m going to split this tutorial into 2 parts.

  • Part 1 – Will be how to setup your DNS and Apache to take all domains that are pointed at it and forward it to the same file.
  • Part 2 – Will cover how we’re going to hand the data structure with a database.
  • Part 3 – Will finish it up with the file to control the traffic based on looking at the data structure.

Let’s get going.

How to point your domains at your server using Namecheap.

Since I’m talking to domainers I imagine that most of you know how to handle DNS and how to point your domains at a server. However I’ll cover how I handle it using Namecheap. I’ve mentioned before I’m a huge fan of Namecheap as their control panel and features are fantastic. If you don’t use Namecheap and use some other registrar you’ll need to get your domains pointing to your server on your own.

First thing we’re going to need to get is the Ip address of your server where you’re running apache and we’re going to be pointing your domains at. If you don’t know this the easiest way is going to be to use a command like ping to the server if you’re used to using a domain. you’ll get back a number that has 4 parts separated by periods called an IP address. This is where we’re going to point your domains at when we login to namecheap. Let’s use oooff.com as an example. Lets say I didn’t know the IP of oooff.com there’s a few ways we could get it. One way would be just ping the address by going to start/run then typing in “ping oooff.com”. Or there’s a lot of services out there to get IP’s for example you can go here., put in the domain server domain and it’ll return a number that looks like this 64.202.163.77. This is going to be the IP address for oooff.com.

Once we have the IP address we’re going to go to namecheap and login like you normally do. Go to manage domains then click on the domains or select all the domains and hit bulk edit for the domains you want to point at this server. Next we’ll click on “All Host Records” in the left menu column. Once we’re in all host records we’re concerned with the two spots at the top. the “www” and “@”. The “www” is of course going to be where you want the http://www.oooff.com sent and the “@” is going to be where you want http://oooff.com sent. In our case we want them both sent to the same place can you guess what that is? Yep the IP address we got using the ping tool. Also we want to set “Record Type” on both to “A (Address)” as this will use the Namecheap name servers and point them at that IP. Typically this will take 5-10 minutes to update but once this time has passed when you put the domain in your browser you will probably get the default page for you server, a 404 cause your server isn’t setup to handle random domains pointing at it, really just something different then you were getting when you started.

Now that we have our domains pointing to the server we need to do some configure apache to make it do the right thing with the incoming domains. If you’ve never messed with Apache and the Apache Config file before this might be a little intimidating so I’ll make it as simple as possible. Basically the /etc/httpd/conf/httpd.conf file is what controls Apache and tells it how to handle incoming domains basically what folder/directory to send them to. So go to you server via FTP or SSH and find the httpd.conf file. It’s usually in /etc/httpd/conf/ directory if not you might need to do a little searching around to find it. Once you find it open it up and take a look through it. What we’re concerned about is the lines right towards the bottom. Called the VirtualHhost section. There’s a couple of lines in that section we’re concerned about.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

This tells the server to use domain base Virtual Hosting which is what we want to do. Then the second lines we care about are

<VirtualHost *:80>
DocumentRoot /var/www/html
</VirtualHost>

What this section is saying is take any incoming domain that doesn’t have a specific record and send it to that location on the server. Now the /var/www/html dir is the default for most apache servers. If yours looks like this we only need to change one thing and that’s to change the document root to somewhere else where we’re going to put our PHP file that’s going to handle all our incoming domains. If that directory doesn’t exist then I suggest making it :) In our example we’ll make a directory dcontroller in /var/www/html. So our virtual host entry would look like this

<VirtualHost *:80>
DocumentRoot /var/www/html/dcontroller
</VirtualHost>
And that’s it. Just save the file then restart your Apche if you’re in on the comman line via SSH just type “server httpd restart”. Or if you have a CPanel/WHM setup you can go to the interface and restart the server there. Now if you have a hard time with this just ask your hosting company as they can easily do it for you. However it’s a great thing to know how to do and understand. Every little piece helps.

Now lets test is our setup is working right. One last piece we’d need to test our setup is working it putting a index.html file in our new directory. Just make a little html file that has a “<h1>Working</h1>” in it. Save this file then go to your browser and type in the domain you setup to point to your server. If you see “Working” displayed in the browser you know you’re golden. If not you know something went wrong. Just contact your hosting support and they’ll guide you I’m sure.

That concludes part 1 of the domainer time redirection system, I’ll try and get the next part written in the next week. Let me know if you have any questions or suggestions and I’ll help if I can. I’m no *nix expert, I just know enough to get by :D

Powerful Open Source ( FREE ) Click tracking tools to improve your Pay Per Click Conversions

Couple of great open source resources for Heat Mapping and click path tracking. Find out where people are clicking and how long they’re staying.

http://www.labsmedia.com/clickheat/index.html

Also if you have a complex site and are looking to track paths of your visitors to find out where they’re leaving you can check out.

http://www.phpopentracker.de

It has the capability of adding plug-in’s to it that will allow you to track conversion. It’s written in PHP and easily extendable to suit your needs. A great place to start if you want to create a full fledged tracking system for and E-commerce site or a large scale site with paths to a sale.

More Advanced Click & Keyword to DirectTrack System Conversion Tracking

keyword tracking statistics

If you’re in a highly competitive niche where pay-per-click, clicks cost 2-10$ per click you need to do everything you can to improve the conversion ratio’s of those highly expensive clicks. As I’m rather new to Pay-Per-Click advertising I’m learning as I go probably just like a lot of you.

In checking my stats and watching my logs ( making myself crazy ) I found that certain days of the week never seemed to produce conversions. So I decided to stop advertising on those days and what do you know my conversion ratio’s and return went up quite a bit. I don’t know why but certain days of the week people like to click ads but not take action for a couple of my niches. With that said I was wondering if there were certain times of the day that leads didn’t convert. Now I’ve run a lot of BlackHat leads to offers in the past and being as it didn’t matter when what converted I had never looked into tracking at this level, sure wish I would have. Needless to say, times of the day made quite a difference and increased my return on investment even more.

If you’ve been following my blog you’ve probably read through my blog you probably saw the last script I put up on tracking which keywords convert for you. In wanting to check if things converted at certain times of the day the old tracking method I was using wasn’t going to cut it anymore. Because DirectTrack, which is the affiliate system Copeac, CPAEmpire and various other smaller companies I work with run on, doesn’t give you a time only a date. So we need to reinvent how we’re going to do our tracking. Rather then by keyword like in the last tracking script we’re going to track the specifics of every click to the database.

The general premise is that rather than having a keyword ID in the database with a count attached to it we’re going to track each and every click that comes through the site. And rather then having the keyword ID passed for the subid to match those up we’re going to pass the click ID. Then when we go to pull and analyze what converted we can see where the click originated, where the click came from, what keyword triggered it, what time it was, etc.

With this layout there’s going to be a tracking.php file that will be included in the landingpage.php file that will record the click and then return the id for the recorded click. Then that id will be replaced in anything that references the affiliate link.

Layout:

First we’ll have our file somelandingpage.php this is the actual page the user is going to be going to. Very simple for this example we’re going to just make it pretty much blank. We’ll just add a couple things so we can test things properly. Of course you can just add whatever you want to the page later or move the code to a real landing page.

<?
$site = “mydomain.com”;
include(“tracking.php”);
?>
<h1>My landing page</h1>
<a href=”http://www.afffiliatelink.com/affid/offerid/<? echo $id; ?>”>link</a>

That’s it! Let’s talk about what’s going on with somelandingpage.php.

First we’re setting the variable $site which will be used in tracking.php which you’ll find out about very shortly. This is going to be the value to track which site or page the click that’s being recorded came through. In our example case we’re going to use a fictitious domain, mydomain.com. So in the database the click will be recorded as coming through mydomain.com. This will allow us to track a lot of domains or pages in the same db. Something else you might do is if you’re split testing landing pages you can just setup two different ones then rotate between them and give them different site names. Then the clicks will be tracked for each page in the db.

Next we’re including the file tracking.php file which will be what we discuss next. If you don’t know, whenever we include a file that means execute the code in the file just like it was written in the somelandingpage.php file itself. It executes it inline just like it was in it. This allows us to make one tracking file and then include it in a lot of pages.

Then we close out the PHP code and put a little HTML just so we can see on the screen that that page actually loaded. The last line of the file is going to give us the link to an offer with the click ID for the click data we inserted. You’ll see how this works shortly. Just understand that we’re going to passing the click ID for the subid in the affiliate link. Then we can go back later and match up the subid on the conversions and match it up with the click ID to see everything about the originating click.

Now lets talk about the tracking.php file.

So tracking.php is going to be the file that’s included on the landing page. Now keep in mind if you have 100 pages on a site and you want to track each one all you have to do is do is set the $site=”site.com/thispage.html”; and include(“tracking.php”); then it’ll start tracking clicks on that page as well.

The gist of the script is

1. we connect to the db
2. we get some environment variables that are set by the server (ip address, referrer, useragent)
3. get data being passed in the url. I’m tracking keyword and source of the click. Now we could get the source through the referrer but setting it when we run our ads is a lot more reliable.
4. we insert the data we gathered into the database.
5. get the id of the record we just inserted.
6. remember the affiliate link in the previous file? Well now we just echo out the id into it where the subid goes and we have the click tracked in the subid. So if that click converts we can go back and see where the click came from, what time it was, what keyword it was. All important stuff wouldn’t you say?

<?
//connecting to the database we setup
DEFINE(‘DB_HOST’,’localhost’);
DEFINE(‘DB_USER’,’login’);
DEFINE(‘DB_PASS’,’password’);

DEFINE(‘DB_PRIMARY’,’tracking’);

mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_PRIMARY);

// Server variables
$ip = $_SERVER[‘REMOTE_ADDR’];
$referer = $_SERVER[‘HTTP_REFERER’];
$useragent = $_SERVER[‘HTTP_USER_AGENT’];

// capturing data we passed in the url
//ie. http://domain.com/page.php?k=my+keyword&s=yahoo
// I’ve added the engine the click is coming from as
// I’m starting to branch out to other engines now
$keyword = trim($_GET[‘k’]);
$source = trim($_GET[‘s’]);

$sql = “INSERT INTO `clicks` (`keyword`,`source`,`ip`,`referer`,`useragent`,`time`,`site`) VALUES (‘$keyword’,’$source’,’$ip’,’$referer’,’$useragent’,NOW(),’$site’)”;
mysql_query($sql);

$id = mysql_insert_id();

?>

Lastly here’s the Database structure you’re going to need. I created a new database called “tracking” and added the table “clicks” with fields for each data piece we want to hold. Here’s the SQL for the click tracking table:

CREATE TABLE IF NOT EXISTS `clicks` (
`id` double NOT NULL auto_increment,
`keyword` varchar(255) NOT NULL,
`source` varchar(255) NOT NULL,
`ip` varchar(15) NOT NULL,
`useragent` varchar(255) NOT NULL,
`referer` varchar(255) NOT NULL,
`time` datetime NOT NULL,
`site` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;

Now all you have to do is go and pull your advanced report from your directtrack based affiliate system. Or any affiliate system that supports SubId’s. And match up the subid’s on your conversions to your click ID’s. Then you know exactly what’s converting for you when.

Next post I’ll cover Building a table for the conversion records and how to automate pulling the data from the directtrack system to populate it. Also I might show you how to make a little system to see what Conversion ratio you’re getting for what words. The last thing which I haven’t implemented myself if finding what bids on words are costing, which could be referenced from reports from the ppc engines.

Stay Tuned!