Jump to content

Referral system


Recommended Posts

Hi,

 

Im about to start building a referral system for my website only im struggling to get my head around the theory first, my website is credit based so for every user you get signed up you receive X credits...

 

I plan on the following...

 

Say user X has the referral link http://www.mysite.com/referral.php?ref=123

 

When somebody visits referral.php, a query is run and adds 10 credits to the user whose ref = 123.

 

My only problem is I need it to only run the query if they visit the referral link, and then regsiter.

 

Sorry if this is confusing, any input would be great, thanks

Link to comment
Share on other sites

This is just basic, you're gonna have to change it a bit ;)

if(isset($_GET['ref'])){ // if the ref variable is set
$ref = $_GET['ref'];

$query = mysql_query("UPDATE `table` SET `credit` = `credit` + 10 WHERE `ref` = '$ref'");
if (mysql_num_rows($query) !== false){
//ok, done, now display the register form off yours
}else{
     echo 'An error Has just eccured, try again later ';
}

}

 

Like I said earlier, this is just a basic example and non secure you'll have to make some changes ;)

Link to comment
Share on other sites

A couple of notes. 

 

1. You need to limit it somehow, so that one person cannot sign up a bunch of accounts under one user.

2. I would set up a trigger that occurred AFTER the registration process, that would add the credit to the user.

    That would save from a user getting credits on referrals that didn't complete the process.

 

Mysql Trigger

 

 

Link to comment
Share on other sites

In the authentication page, you should add this script

 

<?php

if (isset($_POST['ref'])) {
$ref = $_POST['ref'];
$query = mysql_query("UPDATE `table` SET `credit` = `credit` + 10 WHERE `ref` = '$ref'");
if (mysql_num_rows($query) !== false ) {
echo "Thanks for registering. You were referred by" . $ref . ". He will be given 10 credits for it. Be a referral.";
}
else {
echo "Thanks for registering!"
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.