Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Referral Links

  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Referral Links

    Hey,

    Im trying to make a referral script that will log how many individual visitors a person has referred with their link. For instance: they sign up for the referral program and get their own link:

    If someone goes to this link:
    Code:
    http://mysite.com/index.php?=Xibe
    Then it would check the person's IP (to see if they have already been counted in the referral system before), then if they haven't been counted... it would log one new click for the user: Xibe.

    How can I make something like this?

    Thanks,
    X

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hey why don't you try something like this

    PHP Code:
    <?php
    if(isset($_GET["user"]))
    {
      if(empty(
    $_GET["user"]))
      {
        die(
    "User must be selected");
      }

      
    $user $_GET["user"];
      
    $ip GetHostByName($_SERVER["REMOTE_ADDR"]);

      
    $connect mysql_connect("my_server""my_username""my_password");
      
    mysql_query("my_db"$connect) or die(mysql_error());

      
    $sql "INSERT INTO referals (username, ip) VALUES ('$user', '$ip')";
      
    mysql_query($sql) or die(mysql_error());
      }
    ?>
    just make sure the ip address field is set as the primary key or as unique to avoid same ip addresses adding to the users referral count.

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts

    Thumbs up

    Quote Originally Posted by usik View Post
    Hey why don't you try something like this

    PHP Code:
    <?php
    if(isset($_GET["user"]))
    {
      if(empty(
    $_GET["user"]))
      {
        die(
    "User must be selected");
      }

      
    $user $_GET["user"];
      
    $ip GetHostByName($_SERVER["REMOTE_ADDR"]);

      
    $connect mysql_connect("my_server""my_username""my_password");
      
    mysql_select_db("my_db"$connect) or die(mysql_error());  //you had query here.

      
    $sql "INSERT INTO referals (username, ip) VALUES ('$user', '$ip')";
      
    mysql_query($sql) or die(mysql_error());
      }
    ?>
    just make sure the ip address field is set as the primary key or as unique to avoid same ip addresses adding to the users referral count.
    You accidentally used mysql_query twice and meant to use select db
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #4
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    lol thanks was testing the example on my laptop but was on the forum on another computer so i had to write it in manually and im used to typing mysql_query alot more than mysql_connect_db


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •