+ Reply to Thread
Results 1 to 5 of 5

Thread: [PHP] Refferal System

  1. #1
    Newbie Overload will become famous soon enough
    Join Date
    Sep 2009
    Posts
    15

    [PHP] Refferal System

    Hey,

    This is a basic referral system i typed up while in school, It roughly took 15 mins. So here goes.
    We start off with the database structure:
    Code:
    CREATE TABLE `referral` (
    `id` int(11) NOT NULL auto_increment,
    `URL` varchar(255) NOT NULL default '',
    `hits` varchar(255) NOT NULL default '',
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM;
    The next part is the actual file to log the clicks. referral.php:
    Code:
    <?
    $connect 
    mysql_connect("localhost","DATABASE USERNAME","DATABASE PASSWORD");
    mysql_select_db(DATABASE NAME) or die(mysql_error());
    $URL $_POST[URL];
    $URL mysql_real_escape_string($URL);  
    $check mysql_query("SELECT * FROM referral WHERE URL='$URL'");
    $data mysql_fetch_array($check);
    $check mysql_num_rows($check);
    if(
    $check>0)
    {
    echo(
    "Error. Refferal URL/ID is invalid.");
    exit();
    }
    $hits $data[hits]++;
    $update mysql_query("Update referral set hits = '$hits' where id = '$data[id]'");
    echo (
    "<meta http-equiv=\"Refresh\" content=\"0; URL=http://$URL\"/>Thank You! You will be redirected to $URL");
    ?>
    Code:
    $connect mysql_connect("localhost","DATABASE USERNAME","DATABASE PASSWORD");
    mysql_select_db(DATABASE NAME) or die(mysql_error()); 
    The above code defines the database we intend to connect to. This will be the database you put the above mySQL database structure into.

    Code:
    $URL $_POST[URL];
    $URL mysql_real_escape_string($URL);  
    $check mysql_query("SELECT * FROM referral WHERE URL='$URL'");
    $data mysql_fetch_array($check);
    $check mysql_num_rows($check); 
    The first line of this catches the name of the link that has been clicked so any links will always be like refferal.php?URL=thesitename.com. (Ive added a mysql injection prevention code).
    The next few lines are different check functions to gather information from the database to declare if the URL is vaild.

    Code:
    if($check>0)
    {
    echo(
    "Error. Refferal URL/ID is invalid.");
    exit();

    This part will check if there is a row in the database that is the same as the URL gathered by the URL variable. If there is no row like this an error message will appear.

    Code:
    $hits $data[hits]++;
    $update mysql_query("Update referral set hits = '$hits' where id = '$data[id]'");
    echo (
    "<meta http-equiv=\"Refresh\" content=\"0; URL=http://$URL\"/>Thank You! You will be redirected to $URL"); 
    The first line collects the current number in the database and then adds +1 onto it and then the next line saves the new number in the database. The last line will then finally redirect the person to the website.

    Inportant Notes
    • All url's wising to be counted must start like so referral.php?URL=
    • You must use PHPmyadmin to enter the links to be counted or another mySQL database manager.

    Hope this helps, Adam

  2. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,750
    Blog Entries
    97

    Re: [PHP] Refferal System

    Very cool, Adam! +rep

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    37
    Posts
    13,138
    Blog Entries
    58

    Re: [PHP] Refferal System

    Very nice! +rep
    CodeCall Blog | CodeCall Wiki
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #4
    Guru debtboy is just really nice debtboy is just really nice debtboy is just really nice debtboy is just really nice debtboy is just really nice debtboy's Avatar
    Join Date
    Aug 2009
    Location
    I'm in the... Black Lodge
    Posts
    908

    Re: [PHP] Refferal System

    Good Tutorial +rep
    The owls are not what they seem...

  5. #5
    Code Warrior
    /////////|||||\\\\\\\\\
    amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama's Avatar
    Join Date
    Aug 2007
    Location
    Pyramids, Egypt
    Age
    21
    Posts
    8,628
    Blog Entries
    12

    Re: [PHP] Refferal System

    nice work
    thnx for sharing it +rep
    yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. LiveUSB - Take your system with you ANYWHERE!
    By marwex89 in forum Tutorials
    Replies: 17
    Last Post: 08-25-2009, 08:13 AM
  2. Cracking the System - Vulnerability Assessment
    By Showstopper in forum Security Tutorials
    Replies: 0
    Last Post: 07-14-2009, 08:24 AM
  3. Whats new in kaspersky 2010
    By awazdohamko2004@gmail.com in forum Technology Ramble
    Replies: 4
    Last Post: 06-22-2009, 09:00 PM
  4. System Integrity Monitor
    By phpforfun in forum Linux Tutorials, Guides and Tips
    Replies: 1
    Last Post: 01-11-2009, 11:17 AM