Home > Programming, Servers & Scripts >

Fastest PHP redirector possible? (26)


11-13-2011 07:05 PM #1 ipomea (Member)
Fastest PHP redirector possible?

I have a vps in servint with cpvlab. I did a test to see how much traffic would I lose if I use it for mobile. It ended with a loss of 40%.

So I decided to direct link and run some campaigns. But this isn´t working either. Something big is missing.

Say you want to change the link, or add a variable, or even rotate offers. You cannot. You have to build the campaigns again and wait for approvals.

It sucks...

So I´m looking for the fastest solution to redirect without losing any (or the least possible) traffic.

My questions:

- Can I and would it help to host a php file in amazon to handle the redirects?

- Can any php coder here provide the fastest php redirect script?

- This one is for Alex: any update/solution on this issue?

Thanks everyone in advance.


11-13-2011 07:56 PM #2 Smaxor (Veteran Member)

<?php
header('Location: http://www.example.com/');
?>


11-13-2011 08:19 PM #3 nickkk (Member)

^^^^^^^^^^^^^ this


11-13-2011 08:34 PM #4 ipomea (Member)

Thanks smaxor, thats a start. Now how do you:

- pass a subid to the redirect
- redirect by country
- rotate urls by country


11-13-2011 09:44 PM #5 zeno (Administrator)

Quote Originally Posted by ipomea View Post
Thanks smaxor, thats a start. Now how do you:

- pass a subid to the redirect
- redirect by country
- rotate urls by country
Code:
http://redirectdomain.com/index.php?subid1=A&subid2=B&subid3=C&subid4=D
Code:
<?php

   $subid1 = $_GET['subid1'];
   $subid2 = $_GET['subid2'];
   $subid3 = $_GET['subid3'];
   $subid4 = $_GET['subid4'];

   $country = getenv(GEOIP_COUNTRY_NAME);
   $country_code = getenv(GEOIP_COUNTRY_CODE);
   
switch($country_code) {
case 'DE':
$redirect[0] = 'http://someaffurl.com&s1=".$subid1."&s2=".$subid2."&s3=".$subid3."&s4=".$subid4;
$redirect[1] = 'http://anotheraffurl.com&s1=".$subid1."&s2=".$subid2."&s3=".$subid3."&s4=".$subid4;

$number = mt_rand(0,1);

header("Location:$redirect[$number]");
exit;

case 'US':
header("Location: http://someaffurl.com&s1=".$subid1."&s2=".$subid2."&s3=".$subid3."&s4=".$subid4);
exit;

case 'CA':
header("Location: http://someaffurl.com&s1=".$subid1."&s2=".$subid2."&s3=".$subid3."&s4=".$subid4);
exit;

default: // exceptions i.e. unlisted countries
header('Location: http://offerpage.com');
exit;
} 
?>
You will need to have mod_geoip installed on your server in either php or apache form, geoip code at top will change accordingly. Above is when using Apache mod_geoip. I have included a URL rotation for the first country to demonstrate, can use it individually per country.


11-13-2011 09:58 PM #6 ipomea (Member)

Awesome Dave, thanks. I´m trying this now.


11-13-2011 10:35 PM #7 ipomea (Member)

It works like magic.


11-13-2011 11:13 PM #8 zeno (Administrator)

Sweet! I like to test with all countries using Overplay to make sure it's working well. Ctrl+shift+K in Firefox for web console = can see the redirects, magic.

Also, if you are getting stuff approved (e.g. on Facebook) I recommend putting // at the start of every line from
switch($country_code) {
down to
}
except for header('Location: http://offerpage.com');

That way you comment everything turning it into a simple redirect to the offer page, avoiding approvers being redirected poorly, and firing off impressions on your network and screwing up your EPC readouts for the day. Then uncomment afterward and ready to go!


11-14-2011 12:17 AM #9 hd2010 (Member)

throw apache into the dustbin, use nginx


11-14-2011 08:43 PM #10 ipomea (Member)

@ hd2010 thanks for your comment, I´ve been reading about nginx, didn´t know about it. It seems that you can install it in your apache VPS. I will talk to servint about it.

Dave, I use HMA and the "live http headers" firefox addon. Was thinking to use a simple redirect first and then replace it with this one.

A question: Is there a way, by adding some code, to check how much traffic I´m losing by using that redirector?

--

The final part would be to integrate and redirect by carriers, IOS and mobile devices (as some offers require so), but that´s a little more complex.


11-15-2011 01:08 AM #11 zeno (Administrator)

Do you mean how many clicks are bouncing to the exclusion URL rather than through to your affiliate URLs? Or how many people are bouncing off due to possible long redirect times (which shouldn't happen)? There should be very little difference cf. direct linking, the php redirect is server side and happens very quickly.

Coding user/traffic tracking like that is way beyond my coding knowledge, but for looking at raw click loss I just look at clicks from my traffic source vs clicks registered at the network. If there is a big discrepancy I just ask my AM - most of the time with my FB campaigns when I'm running volume I get about 80-90% of my clicks registering on the network side due to duplicates and out-of-geo clicks, seems to be pretty much the norm, unfortunately.


11-15-2011 07:58 PM #12 ipomea (Member)

I meant the second. The first I can know by adding a dif. subid to the exclusion url. The second is more difficult as the network always shows less clicks. But it´s ok.
I´ve installed nginx and it seems that the speed improved a bit. I´ll try to run a load test to see how well is performing.


11-25-2011 12:33 AM #13 harrypotter (Member)

made a few mods cause i want to use it as a redirect for level 1 landing page sequence in cpvlab.

so:

Code:
http://yourdomain.com/redirectpage.php
Code:
<?php

header('Location: http://yourdomain.com/base2.php');

?>
this would go in the <head></head> or the page or the <body></body> of the page? Does it matter?

The above would be faster than something like this?

HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="0;url=http://yourdomain.com/base2.php">
</head>
<body>
</body>
</html>
thanks for the help!


11-25-2011 04:55 AM #14 harrypotter (Member)

Quote Originally Posted by harrypotter View Post
Code:
http://yourdomain.com/redirectpage.php
Code:
<?php

header('Location: http://yourdomain.com/base2.php');

?>
this would go in the <head></head> or the page or the <body></body> of the page? Does it matter?
found this: http://php.net/manual/en/function.header.php

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
so i guess the answer is before ANYTHING... and the page doesn't need <head> or <body> tag because the code won't execute anyway?

thanks for confirming


11-25-2011 03:38 PM #15 kyleirwin (Member)

Yes, you're correct. The header redirect needs to be before any HTML, and no HTML is necessary. Literally all you need in the .php file is...
[php]<?php
header('Location: http://www.yoururl.com/');
?>[/php]

A header redirect will also be faster than any client side redirect, like a meta refresh, or javascript redirect.


02-09-2016 05:01 PM #16 TheComedian (Member)

I've been trying to do this with Voluum but I keep losing the click id. I don't really know how should I do it with:

Voluum url -> redirect.php -> offer.

but I'm getting error, what should I put in the redirect php? because

<?php
header('Location: http://XXXX.voluumtrk2.com/click');
?>


doesn't work


02-09-2016 06:48 PM #17 nickpeplow (AMC Alumnus)

I'm not sure technically how it will stack up performance wise.... but cloudflare has this functionality in their page rules


02-09-2016 10:13 PM #18 TheComedian (Member)

thnak you for your response, but in this case will forward the click information? being that the click info is passed via cookie?


02-10-2016 03:48 AM #19 zeno (Administrator)

Quote Originally Posted by TheComedian View Post
I've been trying to do this with Voluum but I keep losing the click id. I don't really know how should I do it with:

Voluum url -> redirect.php -> offer.

but I'm getting error, what should I put in the redirect php? because

<?php
header('Location: http://XXXX.voluumtrk2.com/click');
?>


doesn't work
Why exactly are you doing this? It seems odd to send traffic from a comprehensive redirection-controlling system to a page that does another redirect, when the initial system could have accomplished this far more gracefully...


02-10-2016 09:10 AM #20 TheComedian (Member)

I wanted to add a layer of "security" between me and the offer. You suggest that the 302 double meta refresh is enough?


02-10-2016 10:41 AM #21 caurmen (Administrator)

@TheComedian - double meta refresh (DMR) is for specifically this purpose, and most affiliates, including the very technical ones, generally consider it enough. It's easy enough to test - set up a test campaign with DMR, run through it with a bunch of different browsers, and see if it successfully cloaks the referrer.


02-10-2016 11:04 AM #22 TheComedian (Member)

oh, perfect then, I was in doubt that it might not be enough as I saw some landers that have this base.php or redirect.php file, and I thought I might need it.
but if DMR from Voluum is enough, great thank you all for your help


02-11-2016 03:10 AM #23 zeno (Administrator)

Yes I would strongly suggest not adding another layer unless its mission critical, in which case I would have a cloaking platform inbetween rather than a manual redirect file.


05-10-2017 04:14 PM #24 poker007 (Member)

Hey caurmen, Zeno, and others who might be able to help. Going along with the previous few posts and cloaking, I'm wondering how does HTTPS play into things if using a double meta refresh (DMR)?

I'm not too sure what the DMR is or how this is performed, but initially I was thinking an HTTPS domain was needed for cloaking so I'm wondering if HTTPS is still needed with a DMR or if HTTPS is unnecessary with DMR? Hope that makes sense.


05-11-2017 09:05 AM #25 caurmen (Administrator)

If you're going from an HTTPS (you) to an HTTP (affiliate network) connection then the referrer shouldn't be passed. There are some reports of referrers "leaking", but they're rare and unsubstantiated. You might still want to use a DMR in that case if you're super-paranoid, but it's probably not worth it.

If you're going HTTPS to HTTPS, though, the referrer will be passed at least some of the time - it should technically be all of the time but browsers don't necessarily obey standards. So if your aff network's link is https and your tracker's also https, you'll need a DMR or equivalent.


05-16-2017 09:30 PM #26 poker007 (Member)

Sorry for the delay in response and thanks for the information Caurmen. I currently have my CDN on amazon web services and don't have an HTTPS setup yet. To perform a DMR, this uses php script right which won't work with cloudfront? Does that mean I should go ahead and change my CDN to perhaps rackspace and/or get an HTTPS domain?

Thanks,
Ferg


Home > Programming, Servers & Scripts >