1

Hello Developers i have a task to build a referral site. The objective is to have people share a link with their friends and this link has a unique referral code so that the person join is registered as a follower attached to a client here is my sample code please help me out.

Below is the flow of the registration process

  1. When the reg button is clicked it creates a refcode which is unique for each personal account created

  2. After registration the person gets a link auto generated with the ref code attached which they can share by email or any other possible way

Below is the sample code

//creating reference code

$re =1;
do 
{
    $re++;
    $refcode = "TUG_".$re;

    $checkrefcode = $con->query("SELECT * FROM clients WHERE Refcode ='$refcode'")
    or die (mysqli_error());

    $refcode_inuse = mysqli_num_rows($checkrefcode);
}
while($refcode_inuse >0);

//generating Link

$href = "<a href="localhost/2gther/follower_reg/$refcode.php">";

1 Answers1

0

There are a few steps that you should be doing here. Basically, you want to create a unique ID for each person within your database right? That way you can tie that person to that unique ID within the database. Here is some documentation on that. It's a randomly generated UNIQUE identifier and can't easily be hacked. http://php.net/manual/en/function.com-create-guid.php

You would then want to put that unique id as a parameter on the url of the link you send out. The user that clicks the unique referral link can then get mapped to the person in the database the unique identifier was generated for. That can be done by querying the database based on the parameter of the url. Does that make sense? But realistically, you aren't creating a unique href for people, you will be using the same URL with a unique parameter. It will definitely cut down on code.

Alex Rindone
  • 296
  • 2
  • 9