cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Redirecting with PHP and libcurl

From: Roman Uhlig | Knuepfer Verlag <roman.uhlig_at_knve.de>
Date: Thu, 10 Nov 2005 12:28:37 +0100

Hi list!

I'm currently trying to solve the following problem with PHP and libcurl:

Lets say I have several websites with a lot of links to external websites.
I'd like to track visits to these websites, which I have done with a PHP
redirect script. Furthermore I'd like to appear all my referring websites
under 1 URL in the webstats of the external websites. Let's say I own
website "A", "B" and "C". "A" and "B" are holding links to an external
website "X". My intension is that clicking the link to "X" both on "A" and
"B" results in the same referring website "C" in the webstats of the
external website (let's just assume that this website "X" is reading the
REFERER from the header). So I tried to send these links via website "C"
like that:
<a
href="h**p//www.website-c.com/redirect.php?target_url=www.website-x.com">www
.website-x.com</a>

I could not yet manage to get it working, neither with header("Location:
...") nor with standard HTML redirect, nor with <iframe> and other stuff I
tried. There will always be website "A" or "B" or an empty REFERER inside
the header, but never website "C".

Here CURL comes into play. I tried the following inside the redirect script
on website "C", which basically works:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['target_url']);
curl_setopt($ch, CURLOPT_REFERER, "h**p://www.website-c.com/");
curl_exec($ch);
curl_close($ch);

Now website "C" appears as REFERER in the webstats of website "X". Until
here everything is fine, except:
I would have to filter the target website through a proxy script, or all
relative links on it would refer to website "C" instead of website "X".
Since I don't know what type of external website my links would end up, I
don't think thats a good idea.

Until now, I'm trapped trying to solve this, either with or without libcurl.

If you have any hints or ideas, I would be deeply grateful.
Thanks in advance,

Roman

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2005-11-10