Rewriting URLs with PHP


I have a site which lists products via 3rd party affiliate links. The links are displayed on my site via PHP, I wish to mask the url so it appears to be on my domain, instructions have been provided and implemented but for some reason, the links only work one time then rather than redirecting to the 3rd party site, they redirect to my homepage, as if some sort of Curl or PHP or server caching is taking place.

Here's the documentation:


Retrieve HTML for [url removed, login to view] product unit.

Note: 'fopen wrappers' must be enabled. Requires PHP 4.3.0. or above.



Code by Bob DeVeaux for ECU

This re-writes the ECU link to the same domain as the code


// function for downloading file

function curl_get_file_contents($URL)


$c = curl_init();

curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($c, CURLOPT_URL, $URL);

curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 5000);

curl_setopt($c, CURLOPT_TIMEOUT, 10000);

$contents = curl_exec($c);


if ($contents)


return $contents;




return false;



$ecu_mid = 839; // your member id

$ecu_uid = 20212; // your unit id

$ecu_tracking = ''; // optional tracking id

$ecu_keywords = ''; // optional keywords for random product unit

$ecu_debug_mode = 'no'; // debug mode (yes or no)

$domain = "http://".$_SERVER["HTTP_HOST"];

$path = '/blog';

$ecu_url =

'[url removed, login to view]'.$ecu_mid



// cURL download file.

if($content = curl_get_file_contents($ecu_url))


$content = str_replace('href="[url removed, login to view]',

'href="'.$domain.$path, $content);

print $content;


I then create a [url removed, login to view] file containing the following:

$domain = "http://".$_SERVER["HTTP_HOST"];

$qs = explode('[url removed, login to view]', $_SERVER['REQUEST_URI']);

$url = '[url removed, login to view]'.$qs[1];

header('HTTP/1.1 301 Moved Permanently');

header("Location: ".$url);

And amend [url removed, login to view] to include:

Disallow: /PATH_HERE/[url removed, login to view]

Like I say, it appears to work, and does so on first clicks, but from then on, it doesn't work due to cache or something?!



Skills: PHP, Software Architecture

See more: return path, php software download, php create function, curl software, url rewriting, QS, php debug, php curl http code, tracking php code, php http redirect, php homepage, curl code, retrieve url, php random download url, curl debug, url mask, mask redirect, url mask redirect, php curl via, curl php debug

About the Employer:
( 7 reviews ) Merseyside, United Kingdom

Project ID: #1156534

Awarded to:


Hi, please check your private messages for some details. Thanks

£20 GBP in 1 day
(9 Reviews)

7 freelancers are bidding on average £80 for this job


quick pro help. ftp and escrow required.

£100 GBP in 1 day
(608 Reviews)

We can help in your project, please check PMB and our ratings/reviews to get idea of our experience.

£100 GBP in 1 day
(249 Reviews)

Check your PMB for details!!!

£103 GBP in 1 day
(88 Reviews)

Hi,Let's get it [login to view URL],Bryce

£90 GBP in 2 days
(202 Reviews)

Would be glad to settle down your problem. Please contact me.

£100 GBP in 1 day
(64 Reviews)

Hello, please check PMB, Regards.

£50 GBP in 0 days
(74 Reviews)

Hello, I have ten experience in web development. I would like to work for you. Don't hesitate to contact me. I can start programming now.

£100 GBP in 1 day
(18 Reviews)