Refferal system script [Need help]

+1 Denis Kolbas · January 29, 2015
Hi guys, so i'm green to php and I need very simple refferal system for my new website

so basically:

1. User comes to my web and gets a ref. link such as ex. domain.com/ref?=ID (number)

2. Everytime somone clicks that link he gets +1 on my webiste

I guess this needs a cookie tracking or something..
So i guess its very simple for u guys, but it's science for me and I dont really have time to learn php now, so could someone 
write or help me with this script?

Post a Reply

Replies

Oldest  Newest  Rating
0 Calvin Sienatra · February 8, 2015
No cookies what so ever.. You just need a database and some php knowledge.
For example the link that is sent to friend's email is http://www.domain.com/register.php?ref=12345&refid=bob123
ref as a refferal code and refid as the refferal's username.
<?
//first things first, do some connection to the database
$con=mysql_connect("localhost","root","");  
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

//getting the ref and the refid
$ref = $_GET['ref'];
$refid = $_GET['refid'];

//after the register button is clicked
//some code for the new user registration process
$checkCode = mysql_query("SELECT * FROM tb_ref WHERE ref = '$ref'") or die(mysql_error());
$count = mysql_num_rows($checkCode);
if($count == 1){
  $getUser = mysql_query("SELECT * FROM tb_user WHERE username = '$refid'") or die(mysql_error());
  $userCount = mysql_num_rows($getUser);
  if($userCount == 1){
    while($getrow = mysql_fetch_array($getUser)){
     $points = $getrow['point'];
    }
  }
  $points = $points + 1;
  mysql_query("UPDATE tb_ref SET used='y' WHERE code='$ref'") or die(mysql_error());
  mysql_query("UPDATE tb_user SET point='$points' WHERE username='$refid'") or die(mysql_error());
}
0 Calvin Sienatra · February 9, 2015
Yeah sorry if its an old deprecated code. Not really used to use new syntaxes,  do change the mysql_query to mysqli. 
  • 1

PHP

107,147 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators