1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to write a php redirect which can take an imput

Discussion in 'PHP & Perl' started by thesaintv12, Nov 12, 2010.

  1. thesaintv12

    thesaintv12 Junior Member

    Joined:
    Mar 9, 2010
    Messages:
    142
    Likes Received:
    23
    Hi php Black hatters -

    I use a php redirect script to hide affiliate links, at the moment I have one file per product. What I want to do is have the redirect script take an input, the product id for example and then use an if within the script to redirect to the correct page on the merchant site.

    As you can probably tell I am not that hot when it comes to php, so -
    1. Is this possible?
    2. can you tell me how to do it or point me in the right direction?

    I have done various searches for it, but I think I must not be using the correct 'terms' to describe what I am trying to do.

    Cheers all.
     
  2. Niche-Digger

    Niche-Digger Junior Member

    Joined:
    Apr 3, 2009
    Messages:
    138
    Likes Received:
    17
    Use switch ...

    call /go.php?id=XXX

    then in go.php

    $id = $_REQUEST['id'];

    switch ($id) {
    case "PRODUCT1": $new_url = "target_url1.com"
    break;
    case "PRODUCT2": $new_url = "target_url2.com"
    break;
    default:
    $new_url = "?!?!!";
    }

    if ($new_url) {
    header ("Location: {$new_*****");
    exit;
    }
     
    • Thanks Thanks x 1
  3. thesaintv12

    thesaintv12 Junior Member

    Joined:
    Mar 9, 2010
    Messages:
    142
    Likes Received:
    23
    Thanks so much for that Niche-Digger, just what I was after!

    Rep+thanks given.