I am trying to figure out how to create dynamic links and URLs for a static webpage. What I want to do is the following. I have a single webpage for example:


that will always look the same, except for one link on the page. the link would be on the page for example: LINK TO AFFILIATE:


the only thing would change is the "DYNAMIC_REFERER" with every dynamic url on this page:

  • example.com/INDEX.PHP_id=test1
  • example.com/INDEX.PHP_id=test2
  • example.com/INDEX.PHP_id=test3
  • example.com/INDEX.PHP_id=test4

which would only change the dynamic link on the page to:

  • http://affiliated.example/my-affiliate_code_here_test1
  • http://affiliated.example/my-affiliate_code_here_test2
  • http://affiliated.example/my-affiliate_code_here_test3
  • http://affiliated.example/my-affiliate_code_here_test4

How can I go about doing this?

I just don't want to have to make 100's of pages, as this would prevent me from having to do so.

2 Answers 2


Since your index is PHP, all you need is to modify the link using PHP.

So, in your index.php between the HTML you would have something like:

<a href="affiliate.com/my_affiliate_code_here_<?php echo $_GET['id']; ?>">Link Text</a>

So, when someone goes to: index.php?id=test1

The link would go to affiliate.com/my_affiliate_code_here_test1

That's it! Any script you would find to do this would me more hassle.


The referrer in PHP is in the _SERVER global.


Set a variable in a separate file like $referrer = $_SERVER['HTTP_REFERER']; Include the file in whatever file you want to use this in.

I think this is what you are asking anyway.

  • I am guessing I am going to need a php script to do this. Is there any cheap or free ones out there that could handle this for me?
    – John
    Jan 21, 2011 at 23:23
  • If you have 100's of pages you should really be using a Content Management System like TextPattern, Modx or ExpressionEngine. They all automatically handle URL writing so you can focus on content. They all allow page design too so you can customize them to fit your design. Jan 21, 2011 at 23:34
  • its just one page. I would have to make the same page multiple times, just changing the one link. I would like to make one page that changes the link with the variable in the url. that is what I am looking for.
    – John
    Jan 22, 2011 at 1:10
  • Set up an array with your page structure. Jan 23, 2011 at 18:59
  • Sorry for the short reply above. - If it makes sense, do a associative array. Something like: $array = array('My Page' => '/my_page', 'Another Page' => '/another_page'); Then loop through the array and match the URL to a value in the array. Jan 24, 2011 at 1:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy