When launching a new product or website online, it has become popular to only allow the first set of users in with an invite. Although there are many different ways to accomplish this, here I’m going to show you how to make a system yourself using PHP. This is intended to only show you the bare bones of a system, but if you have any questions, feel free to leave a comment.
What do we need
Here is exactly what we are going to need to make our invite system
- Mysql database
- A php page to accept the email address
And that is really it!
I’m not going to go into depth about creating the database as there are already thousands of tutorials out there that will be able to explain it far better than I can. Below is a screenshot of my simple table that I’ll be using for this tutorial.
Next we are going to create the form that will accept the user’s email address and a button to submit the form to be processed by the PHP. Again, I’m only giving you the bare bones of what you need as there are already thousands of tutorials out there if you are looking for more advanced functionality.## Processing the form
As you can see from the code above, we are going to be processing the form on the same page. To do this we must determine if the submit button has been pressed. This will make a decision to process the form or not. To do this, we will be using the following code.
Next we must get the email address and save it as a variable, like this.
$email = $_POST['email'];
Now at this stage you should do some checks on the email address that was submitted. For Helplist I check to ensure it is a proper email address and check to see if that email address has already been submitted. There are many ways of doing this, and, once again, I’ll leave it up to you to find the right validation methods you want from the numerous tutorials out there on the Internet.
Next we will create the invitation code that will be a unique 10 character string that will be used later to send the invite to the user.
$length = 10; $inviteCode = ""; $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; for ($p = 0; $p And finally, we insert the email address and the invite code into the database.
mysql_query("INSERT INTO invitation (email, inviteCode) Values ('$email', '$inviteCode') ")
Using the invite code
Once people start signing up to your invite system you will get a database of email address and unique invite codes. Once you are ready to start inviting people to your website simply write a script that will send them an email with a link to a file such as register.php?invite=invitecode. The user will then be able to register using their email address that will verify against the invite code in the URL. If they try and share their invite code, the other users won't be able to get access as that invite code won't be registered with their email address.
I hope that was clear and straight forward. With these type of tutorials I always find that they're are too bloated for what I need. I hope by keeping it simple I've allowed you to get what you need to complete your project.
If you have any questions, feel free to leave a comment!