Search code examples
phphtmlrequestinvite

giving users invites?


I want people to request invites to use my app, they fill in their email address, but how can generate an url for them to go to register? Presumably only to be used once! I was thinking some sort of md6 code using php!

P.S. If there is a tutorial for this, please give a the link. Thanks.


Solution

  • In the email you use a random code, for example (a part of) the session-id of the user

    <?php
    $code = session_id();
    

    You save this code somewhere in your database and when the user hits your register page (for example, http://mydomain.tld/register?code=here-register-code), you do something like this:

    <?php
    $code = $_GET['code'];
    if (my_code_is_valid($code) {
        echo 'Hey, you are able to register now!';
    } else {
        echo 'Sorry friend, you need an invite first!';
    }
    

    You need to define your my_code_is_valid() function, but that's depending on your own code (framework, database system etc).