PHP code example of jasny / invite-code

1. Go to this page and download the library: Download jasny/invite-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jasny / invite-code example snippets


Jasny\InviteCode::setDir('invite-codes');

$invite = new Jasny\InviteCode($_POST['invite']);

if (!$invite->isValid()) {
    echo "Invalid invite code";
    exit();
}

if ($invite->isUsed()) {
    echo "Invite code is already used";
    exit();
}

$invite->useBy($_POST['name']);

mkdir invite-codes
cd invite-codes
for i in {1..100}; do
   CODE=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'A-Z0-9' | fold -w 8 | head -n 1)
   touch $CODE
   echo $CODE
done