title: Redirecting user for Invite/Referral System
body: <p>I have created an invite/referral system that allows users to invite someone by entering a email address, the email and a the random invite code is stored in the 'referrals' table. An email is then sent out to that person with their email and unique 10 character invite code in the URL link e.g. www.website.com/register.php?email=(emailaddress)&amp;invite_code=1234567890</p>
  
  <ul>
  <li>I have made some changes, the following script is now in should be redirected to register.php if not then back to the homepage. </li>
  </ul>
  
  <p>I have tested this, and even with a valid URL link users are still redirected to the index.php page. (Also this doesn't stop users from accessing register.php manually)</p>
  
  <p>Table details = 'referrals' with ID | URL | hits | email | inviteCode </p>
  
  <p>I have managed for the page to redirect, though this is no good if they have an actual invite code for their email. </p>
  
  <p>Here is the script I have been modifying the past couple days to try to get working: </p>
  
  <pre><code> &lt;?php 
  
     include 'config.php';
  
     if (isset($_GET['email'],$_GET['inviteCode']))   {   
  
   $mysqli        = new Mysqli(/* your connection */);
   $email         = $mysqli-&gt;real_escape_string($_GET['email']);
   $inviteCode    = $mysqli-&gt;real_escape_string($_GET['inviteCode']);
   $sql           = "SELECT email,inviteCode FROM referrals WHERE email='$email' AND    inviteCode='$inviteCode'";
   $query     = $mysqli-&gt;query($sql);
  
   if ($query-&gt;num_rows) //check if values are correct and available in database
     {
       header('Location: register.php');
         }
       else
           {
       header('Location: index.php');
       exit;
           }
     }
  else
     {
  header('Location: index.php'); //Page not accessible if neither email nor referral entered
     }
  
  ?&gt;
  </code></pre>
  
  <p>It should be straight forward, check the URL for the 'email' &amp; 'inviteCode' compare with the table if they have been invited allow access to the page if not redirect. &lt; With the updates they should either be redirected to register.php or index.php. This does not stop access to register.php if accessing without invite. </p>