When a user goes to any of those URLs I want a script to respond to the action by redirecting the user to a primary site that I already have a hosting plan for.
If you get a hosting service like hostgator (not trying to drop names, but this is what I use), you can setup/buy a baby server, which allows you to use as many domain names on 1 hosting server as you please, as long as they are not for reselling purposes. They have a interface section that literally allows you to point the domain you have to any other domain on that list, without you needing to write any code yourself. I'm 100% sure there are other companies that have these services, but i don't know any off the top of my head.
And I'll want a counter on the page of each ancillary domain as well.
In the cpanel, you'll see a hit counter that shows you what each domain is getting hits wise, and fancy graphs and stats you'll.
That being said, these pieces of code are all over the place, and is actually off topic in super user, you might want to try stackoverflow instead.
I personally don't see a reason in getting a count in the re-directed domain when you're main focus is to see how many hits you get on your primary domain, (my 2 cents)