1. Go to this page and download the library: Download garphild/auth-telegram 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/ */
garphild / auth-telegram example snippets
use Garphild\AuthTelegram\TelegramAuthentificator;
define('BOT_USERNAME', 'XXXXXXX'); // place username of your bot here
define('BOT_KEY', 'XXXXX:XXXXXXXXX'); // place @botFather key of your bot here
define('BOT_COOKIE_NAME', 'XXXXXX'); // place cookie name to store data
$config = [
'resultActionType' => 'url',
'resultAction' => 'check_authorization.php',
...
];
$tgAuth = new TelegramAuthentificator(BOT_USERNAME, BOT_KEY, BOT_COOKIE_NAME, $config);
if (isset($_COOKIE["tg_user"])) {
$tgAuth->setUser(new TelegramUserModel(json_decode($_COOKIE["tg_user"], true)));
}
if ($_GET['logout']) {
$tgAuth->logOut();
setcookie("tg_user", null);
}
if ($tgAuth->isAuthentificated()) {
... user authentificated ...
} else {
... not authentificated ...
echo $tgAuth->getWidget();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.