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

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!

How to Track Converting Keywords for your Affiliate Marketing advertising using PHP.

Do it yourself keyword conversion tracking

I started to write this on http://www.wickedfire.com then figured I needed some new content this week.

Have you ever wanted to find out which of your keywords are converting on your campaigns you’re running?

This is actually a relatively simple thing to do if you pass the keyword as your subid. However because we never know who’s looking at our keywords we’re going to want to rewrite the keyword as a number that we have reference to. If you’re traffic to a content site or something other then a straight redirect bounce page, you can track them with a cookie or session or both. So a very simple solution for an affiliate redirect page that tracks your conversion by keyword might be.

<?
include(“dbconnect.php”);

//
$keyword = trim($_GET['keyword']);
$keyword = mysql_real_escape_string($keyword);

// Finding the keyword in the database if it’s there
$sql = “SELECT * FROM keywords WHERE keyword = ‘$keyword’”;
$sql_out = mysql_query($sql);

if($sql_out){

$row = mysql_fetch_assoc($sql_out);
$id = $row['id']; //gets the id associated with the word
$sql = “UPDATE keywords SET count = count + 1″; // sql to increment the counter for that word
mysql_query($sql);

}else{

// This chunk puts our new word in the database and grabs it’s ID
$sql = “INSERT INTO keywords (keyword) VALUES (‘$keyword’)”; // sql to insert the new keyword we don’t have cataloged
mysql_query($sql);
$id = mysql_insert_id(); // gets the id of the record we just inserted.
}

// Here we’re redirecting to the end location with our replaced keyword with the new ID
$location = “Location: http://location.com/subid=$id”;
header($location);

?>

SQL for this is just a table is very simple. Just a 3 fields.

1. id set to primary key and auto-increment
2. keyword set to varchar 200 and indexed
3. count set to double no indexing

And that should do the trick….

This will take the incoming visitor and log the keyword, then redirect to the offer based with the subid for the keyword. This is a straight redirect bounce page with replacement keyword tracking.

Now if you want to track based on them coming to a site do two thing make your page based on php. and at the top put that same code, just remove the header and location lines. Then when you generate your page replace your links with with the $id so for example that php page would look like this.

<?
// previous code here minus the header redirect
?>

<h1> here is some text</h1>
<p> here more text and a <a href=”http://destination.com/subid=<? echo $id; ?>”>link</a><p>

now you’ll see we’re calling the php inline to echo the number we’ve retrieved from the keyword above. Then when you run that page in your browser you’ll see the id’s replaced :) pretty slick huh.

A couple ideas for this that could be added are geoip tracking and redirection based on the location of the visiting guest. Or how about finding out where your visitors are coming from? Do you know if you’re getting natural traffic? And if you do know, do you know where’s it coming from and which of those locations are converting for you? If you found a link to your site that was bringing a lot of nice traffic that was converting it might make sense to run a banner ad or something like that there wouldn’t it?

Tracking is Simple, Powerful and fun using a little PHP ingenuity.

another freebie from http://www.OOOFF.com

Found a Great Design Patterns Book!

First off for those of you who know me at all, you know I’m a huge advocate of learning. I consistently have a bare minimum of 3 books stacked on my nightstand ( sometimes gathering dust, but they’re there ). A book always in my car. Also usually 2-3 books when a travel. With my one goal of doing a little more research to try and pick up just one good idea that’s going to help my php coding, php architecture, marketing copy, negotiations skills, sales skills, motivation, etc etc etc and the list goes on. There’s a very famous quote that says

“If you’re not growing, You’re dying. ”

And I seriously believe this with all my heart. That’s one of my passions about this business is there’s always something else to learn. Whether to do with computers, marketing, sales, business, economics, etc. There’s always something to learn sometimes to my detriment. :)

Just a small background on myself. Back in August of2005 I knew nothing about computers, for the most part. I could muttle my way around Google and check my email. I even understood what a server was but really had no idea much beyond that. About this same time the company I was working for was about to go into bankruptcy so I got laid off and decided I was going to make a go at another off-line business I was already working part time. Now though the plan was to promote it on the internet full steam.

So after messing around with some SEO, buying a few scripts and reading a couple ebooks I decided I really NEEDED to learn to code. It always seemed like the scripts I bought just needed a few more peices for automation. Or the tracking scripts weren’t quite right. Once I decided that I was going to take the leap and teach myself to speak computer I tried to figure out what language would be the best. Because I had an Excel spreadsheet course in college that delved a tad bit into the VB side I decided to jump into that first. WELL VB sucked for what I wanted to do so I shifted over to PHP. [ sidenote - you ever feel like you're on a tangent? that's what I feel like right now. ]

So lets fast forward to the end of last year. I’d been working this business full time for about a year and had picked up some PHP skills through books, trial and error and about 14 hours a day of time. Keep in mind I knew NO ONE in this business at all that could help me forthe most part. I got a little help from the guys in #RSSGM on freenode but not much. By the end of the year I could hack a script together pretty well and could understand most other peoples code. Most of the stuff I wrote really looked like spaghetti was a nightmare to alter, update or maintain. You know what I’m talking about right? Where there’s a couple functions at best! And the rest of the code is like 300-500 lines of all procedural…. Have you ever tried to change or maintain something like that?

As you know things in in the Internet Marketing business can change rather quickly. Let’s say you have a Squidoo lense builder. Today it could work tomorrow they could change the whole thing. Or maybe you built the system around a niche and then you found out another niche was very profitable as well. How hard is it to change your scripts that involve building, research, tracking, interaction with the providers, etc etc. It’s a pain isn’t it if all your code is procedural.

The other thing I was beginning to notice at this time was that I was writing the same code again and again. Think about this for a second. What are some common themes to building an account on something like Blogger or Squidoo. Is there commonalities among those? You betcha! So rather the rewriting your code over and over again I figured there must be some way to make my code reusable or at least build a basic framework for things that I was doing repetitively. Because I’ll be honest with you I really enjoy making the interaction classes. Doing things like tracing headers and figuring out nuances of how to reverse engineer a website or web service. That part is fun to me. However once you have all your interaction classes built, making the management side is usually pretty boring in comparison.

Code architecture… what the fuck is that? That’s what I was asking myself when I first started looking into it. Now keep in mind I’m just a businessman that’s decided to learn how to code out of seeing a great profit potential. I’m as far from a coder as one could possibly get. Or at least was. I think I’m getting closer and closer to being a real coder everyday ( not sure if that’s good or bad ). But that strictly comes out of necessity for building bigger and bigger systems. Now keep in mind this isn’t Windows XP we’re talking about. But the systems I’m building do seem to get larger and more elaborate all the time. Because of this I’ve forced myself to switch to Object Oriented Programming which I knew nothing about 6 months ago.

So back to those books I was talking about in the beginning. I buy at least 2 books a month if not a lot more. Was wasting some time today and went to Borders Bookstore. knowing I really want to learn code architecture basics I’ve been snapping up quite a few books about object oriented coding, design patterns, UML, and Use Cases in order to find one that might help me get one more good idea and put the puzzle pieces into place just a touch more. Typically I’ve been having to buy books that revolve around Java as most architecture stuff is written for Java or C/C#. Java really isn’t hard to understand once you have a firm understanding of how the OOP basics work in PHP.

So at the bookstore I made a couple of purchases today but there’s one I’m really stoked about. and that’s ( drum roll please )

“Design Patterns for Dummies” – Steve Holzne, PhD.

Now, laugh all you want and talk shit all you want but I’ll be straight forward with yah. I’m not the smartest tool in the shed and a lot of times I need things broken down into Engrish ( for you DigitalPoint guys ), especially tech stuff, as that’s not how I think usually. I’m a huge advocate of the for Dummies series yes some of them really do suck. But I’ve bought every non-Dummies book I could get my hands on about design patterns ( probably about 5 – 9 books ) and just haven’t been able to wrap my head around things. Some people just get it, some people don’t. I think I’m one of the ones that don’t. Persistence is the one attribute I do have though, if I really want to do or learn something there’s not much that’s going to stop me. I know some of you have looked at my suggestions for learning PHP and really the for Dummies books are excellent if you just don’t get it or need things broken down and simplified just a little more. Design patterns are a fairly hard concept in my opinion, especially real composition. However there’s some really cool stuff you can do with them that will save you a TON of time in the long run.

On that note I’ve been looking for a good pattern for sometime that I could use to interface a lot of sites that all do similar things. Lets take making blog posts for example. We all know not all public hosted blog sources support XMLRPC. Therefore we might need to do XMLRPC posts to some, form posts to others and maybe email posts to other still. Now just for fun lets say we had 50 different hosts, all places we could host blogs for free.

How could we go about designing a system in such a way that we could treat them all the same and handle them all the same way from a management side?

And really encapsulate the specific functionality of each to be maintained separately?

What are some of the things that might be in common between them? Login(), Post(), UpdateBlogroll()?

Wouldn’t it be cool to be able to treat all these different hosts the same from the prospective of the management layer? Well check out the Factory pattern it might be what you’re looking for…

SQUIRT Link Building Automater….

As most of you know I wrote a tool to automate submissions to SQUIRT, BluehatSEO’s ( Eli’s ) automated link building tool What the script I wrote allows you to do is que a list of domains in a file so you don’t have to go the the site and make submissions everyday. I’ve read on a lot of boards that people were having some issues with it and just wanted to let you know if you’re having trouble please leave your questions here. I tested it again yesterday and it seems to work just fine on my server so maybe you have something configured incorrectly. Some things to check:

  1. Is your cookie dir writable?
  2. Do you have your root directory set right?
  3. Does your cookie dir exist?

Let me know~!

New tutorial on Filling Forms using PHP added

Sorry for the long delay in between tutorials. Looks like about a month and a half. With the summer time here there’s a lot going on non-work related. So if you’ve been waiting for the first newbie tutorial on how to post data to forms using PHP, it’s here!

Basic PHP Form Fill Tutorial

Please let me know what you think. I tried to cover all the steps from start to finish on posting to a form using Curl and PHP. If you have any suggestion to add to the tutorial please leave them here. Keeping in mind this is a super basic all for beginner tutorial. Good Luck!