8 replies
Hi

I had this PHP code but I can't find it where I saved it. The code was to redirect to affiliate sites.

for example

www.something.com/index.php/link1
www.something.com/index.php/link2
www.something.com/index.php/link3

...etc and then there is another text file with arrays link1 redirect to affiliate link1, link2 to affiliate link2, link3 to affialte link3 etc.

Does anyone know how to achieve this with PHP?

Thanks
#php
  • Profile picture of the author SamstaUK
    I don't know how to do this in PHP, but if your server supports perl I'll write a script for you.
    {{ DiscussionBoard.errors[682495].message }}
    • Profile picture of the author AndyBlackSEO
      You could use something like............

      Add your own internal links such as.....

      http://www.mysite.com/product.php?id=2

      Then add the following code to ie - product.php

      <?php
      $affiliate = $_GET['id'];
      if ($id == "1") {
      header("Location: http://www.awin1.com/awclick.php?mid=374&amp;id=67985"); exit; }
      elseif ($id == "2") {
      header("Location: http://www.awin1.com/awclick.php?mid=374&amp;id=67999"); exit; }
      elseif ($id == "3") {
      header("Location: http://www.awin1.com/awclick.php?mid=374&amp;id=67104"); exit; }
      ?>

      This would redirect to your affiliate. Is this what you meant? You wouldn't even need the exit clause as the script wouldn't execute any other functions due to them being in their own 'if' statements.

      You could of course just have one redirect per page.
      Signature
      [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
      ... Instant backlinks that can get you results within 24-72hrs.
      {{ DiscussionBoard.errors[682531].message }}
      • Profile picture of the author WebScript
        In your initial post, you said:
        Originally Posted by blackjack View Post

        Hi

        I had this PHP code but I can't find it where I saved it. The code was to redirect to affiliate sites.

        for example

        www.something.com/index.php/link1
        www.something.com/index.php/link2
        www.something.com/index.php/link3

        ...etc and then there is another text file with arrays link1 redirect to affiliate link1, link2 to affiliate link2, link3 to affialte link3 etc.

        Does anyone know how to achieve this with PHP?

        Thanks
        Am I correctly reading this that there was a text file (not html or php) that looked something like:

        Code:
        link1, http://aaaa.vvvv.hop.clickbank.com
        link2, http://www.example.com/awclick.php?aff=12345
        ...
        If so, a realistic example would help, including if it used commas or spaces or "quotes".

        Or, was it coded in PHP like Andy suggested ?
        Originally Posted by AndyBlackSEO View Post

        You could use something like............

        ...

        PHP Code:
        <?php
        affiliate 
        GET['id'];
        if (
        id == "1") {
        header("Location: http://www.awin1.com/awclick.php?mid=374&amp;id=67985"); exit; }
        elseif (
        id == "2") {
        header("Location: http://www.awin1.com/awclick.php?mid=374&amp;id=67999"); exit; }
        elseif (
        id == "3") {
        header("Location: http://www.awin1.com/awclick.php?mid=374&amp;id=67104"); exit; }
        ?>
        ...

        Originally Posted by blackjack View Post

        It is very similar to what Andy wrote but without ?id=1. It was using function Explode to get the id part from URL i.e. link1 from www.something.com/index.php/link1

        I just can't remember how it was done. I'll keep looking through my harddrive.

        Thanks
        I assume you didn't have a folder named index.php/ here:
        www.something.com/index.php/

        That being the case, it looks to me like you must have been using MOD Rewrite functions in .htaccess in addition to the list of affiliate links

        So, you could check this and report back:
        1) do you still have a current or perhaps backup of your .htaccess file
        2) do you still have a current or perhaps backup of your index.php file
        3) do you remember the procedure you used to create/edit/manage the redirected links

        If you don't have #1 or #2, it's ok, the important thing is #3, or deciding on how you want to define the redirects now.

        Feel free to PM me if you want.

        Kevin
        {{ DiscussionBoard.errors[685540].message }}
  • Profile picture of the author mywebwork
    Not exactly sure from your description what it is your script did, was it just simply redirecting to an affiliate site with your link?

    If it is, you can redirect any page using PHP's "header" command, for example a page with this code would redirect to CNN's site:

    Code:
    <?php
    header( 'Location: http://cnn.com' ) ;
    ?>
    Obviously in your situation you'd replace the CNN link with your affiliate link.

    This is often used when trying to "cloak"affiliate links. You can also achieve the same effect with an HTML Meta Tag.

    Hope this helps, again I'm not really sure what your original script did.

    Bill
    {{ DiscussionBoard.errors[682535].message }}
    • Profile picture of the author blackjack
      It is very similar to what Andy wrote but without ?id=1. It was using function Explode to get the id part from URL i.e. link1 from www.something.com/index.php/link1

      I just can't remember how it was done. I'll keep looking through my harddrive.

      Thanks
      {{ DiscussionBoard.errors[682565].message }}
      • Profile picture of the author DanGTD
        Originally Posted by blackjack View Post

        It is very similar to what Andy wrote but without ?id=1. It was using function Explode to get the id part from URL i.e. link1 from www.something.com/index.php/link1

        I just can't remember how it was done. I'll keep looking through my harddrive.

        Thanks
        If the link above is correct, it can't be done unless you modify your .htaccess file

        Somethink like this

        Code:
        RewriteEngine on
        RewriteRule ^index.php/link([^/.]+)/?$ index.php?link=$1 [L]
        And then in index.php play with the $_GET['link'] parameter.
        {{ DiscussionBoard.errors[686850].message }}
  • {{ DiscussionBoard.errors[686920].message }}
  • Profile picture of the author Adaptive
    Can someone move this to the programming forum please?

    Regards,
    Allen
    {{ DiscussionBoard.errors[687220].message }}

Trending Topics