Simple PHP question that will likely help many

6 replies
I think an answer to this question will likely help many folks on the forum
BTW: I have tried to search the forum and Google long before posting this

My scenario is this:
  • I have built a site Live Smarter Online to promote Auto Recruiting Platform
  • I built it in such a way to help my team members build their own downline
  • I want people from other teams to be able to use it as well
  • I need them to be able to pass their affiliate code to get credit
  • I would like to be able to have aff ids rotate if possible if no one specifically sends their own code
  • I am using WordPress (but I don't think that will make much of a difference)

If you are still with me, thank you. This is difficult to explain in a concise manner.

I am planning to use <? echo $_GET['id'] ?> to insert the promoter's username into all of the links but if someone comes to the site directly, I want to have the link automatically rotate through my downline's usernames, thus helping everyone get more traffic.

I am sure I am not the only person to have thought of this, I just haven't been able to track it down, specifically the rotator aspect.

Does anyone care to take a crack at it?

Thanks in advance!
Mark
#php #question #simple
  • Maybe this will make the rotator part easier to understand, manage and implement:
    • IF: If someone sends people to the site with their affiliate id, it will ECHO their id in all of the site links
    • For example: http://livesmarteronline.com/?id=<? $_GET['id'] ?>
    • IF NOT: If someone comes to the site via Google or traffic I send to it, the links will all contain a URL from an external rotator program I use
    • For example: http://rotatorurl.tld/r/?rotatorid=1

    Something like:

    <?php $TEAMMATE = "<? $_GET['id'] ?>"; ?>

    which would then allow

    <a href="insert domain name here/<?php echo $TEAMMATE; ?>" target="_blank">


    In other words:

    If someone goes to the site via: domain/?id=TEAMMATE all of the links going to the company will give TEAMMATE credit

    If someone goes to the site directly (without an affiliate link), the links will all be served up with URL rotator link that will rotate through my team's usernames and helping everyone on my team more traffic than they would have had otherwise = everyone wins!
    {{ DiscussionBoard.errors[8825703].message }}
  • Profile picture of the author kevbo22
    <?
    if($_GET['id'] > 0) {
    $TEAMMATE = $_GET['id'];
    }else{
    //include your url rotator here
    }
    ?>
    Signature

    The best path to prosperity is free market capitalism!

    {{ DiscussionBoard.errors[8825794].message }}
    • Thanks for the quick reply, kevbo22.

      I am pretty new to working with PHP so thank you for your patience:

      Can you give me an example of how to implement this?

      ie:
      Is your code to be placed in the HEAD tags?

      <?
      if($_GET['id'] > 0) {
      $TEAMMATE = $_GET['id'];
      }else{
      //include your url rotator here
      URL-ROTATOR dot COM
      }
      ?>

      and being as originally my links have been:
      "domain dot com/<?php echo $TEAMMATE; ?>"

      to allow their ID to convert the links and give them credit, would there be a way to have the links go to:

      URL/TEAMMATE link (IF they provided a "?id=TEAMMATE")
      OR
      ROTATOR URL (IF the reader came to the site directly)

      I hope this makes sense.
      I truly appreciate your help.
      I'm designing this as an effort to "pay it forward" as much as I can.

      Thanks,
      Mark
      {{ DiscussionBoard.errors[8825893].message }}
    • Profile picture of the author Brandon Tanner
      I would use isset instead of > 0

      <?php
      if(isset($_GET['id'])) {
      $TEAMMATE = $_GET['id'];
      }else{
      // rotator code here
      }
      ?>


      Also, you should sanitize your $TEAMMATE value before you do anything with it, otherwise you're opening yourself up to all kinds of potentially nasty stuff (XSS attacks, etc). Using htmlspecialchars is a good start, and will protect you from most types of basic attacks.

      $TEAMMATE = htmlspecialchars($TEAMMATE, ENT_QUOTES);


      As per the rotator part, the easiest way (by far) to do it would be to assign each of your teammate's an ID number, and then rotate through them randomly (which should work out to be fairly even over the long run). For example, if you have 3 teammate's, and their referral ID's are Member1, Member2, Member3, etc., then you can do something like this...

      $number = (rand(1,3);
      $TEAMMATE = "Member" . $number;
      echo $TEAMMATE;


      If you'd rather not go the random route, then you would have to keep track of each of your teammate's referral count in either a database or a flat file, then loop through each teammate in the database whenever someone visits the site without an aff link. That would involve a lot more code than the 'random' option though, and I'd definitely recommend hiring someone to code that part if you're new to PHP / MySQL.
      Signature

      {{ DiscussionBoard.errors[8825950].message }}
      • Brandon, that sounds great.

        To clarify:

        <head>
        <?php
        if(isset($_GET['id'])) {
        $TEAMMATE = $_GET['id'];
        }else{
        //rotator dot com
        }
        ?>
        </head>



        And the link would be:

        <body>

        company dot com/<? echo $_GET['id'] ?>

        </body>


        Not sure yet how to implement the:
        $TEAMMATE = htmlspecialchars($TEAMMATE, ENT_QUOTES);
        ...but I really appreciate you bringing that up
        {{ DiscussionBoard.errors[8826049].message }}
        • Profile picture of the author Brandon Tanner
          I would put the initial PHP code block very first thing in the document (before the <html> tag). Then you can put the echo code anywhere you need it in the body.

          As per how to implement htmlspecialchars, just insert the htmlspecialchars line right after you grab the $TEAMMATE value from $_GET...

          <?php
          if(isset($_GET['id'])) {
          $TEAMMATE = $_GET['id'];

          $TEAMMATE = htmlspecialchars($TEAMMATE, ENT_QUOTES);
          } else {
          // rotator code here
          }
          ?>


          Basically, all the htmlspecialchars line does is sanitize (encode) any quotes found in the $TEAMMATE value (because a malicious user would normally need to use quotes to facilitate a XSS attack, yet a legitimate affiliate ID will not normally contain quotes). In the odd case you DO want to be able to use quotes as part of the affiliate ID, then you would simply decode that value whenever you need it (see this).
          Signature

          {{ DiscussionBoard.errors[8826253].message }}

Trending Topics