Dynamic URLs and links to many affiliate links from one PHP page

8,231

Solution 1

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.

Solution 2

The referrer in PHP is in the _SERVER global.

echo $_SERVER['HTTP_REFERER'];

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.

Share:
8,231

Related videos on Youtube

Stephen Ostermiller
Author by

Stephen Ostermiller

Updated on September 17, 2022

Comments

  • Stephen Ostermiller
    Stephen Ostermiller almost 2 years

    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:

    http://example.com/INDEX.HTML
    

    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:

    http://affiliated.example/my-affiliate_code_here_DYNAMIC_REFERER
    

    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.

  • Admin
    Admin over 13 years
    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?
  • Richard Testani
    Richard Testani over 13 years
    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.
  • Admin
    Admin over 13 years
    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.
  • Richard Testani
    Richard Testani over 13 years
    Set up an array with your page structure.
  • Richard Testani
    Richard Testani over 13 years
    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.