<?php
define
('BOT_USERNAME''BaldEagleBot'); // place username of your bot here
function getTelegramUserData() {
  if (isset(
$_COOKIE['tg_user'])) {
    
$auth_data_json urldecode($_COOKIE['tg_user']);
    
$auth_data json_decode($auth_data_jsontrue);
    return 
$auth_data;
  }
  return 
false;
}
if (isset(
$_GET['logout']) && $_GET['logout']) {
  
setcookie('tg_user''');
  
header('Location: i20');
}
?>
<?php 
/*顯示原始碼*/ $file=__FILE__; require("src.php"); ?>
<?PHP
$tg_user 
getTelegramUserData();
if (
$tg_user !== false) {
  
$first_name htmlspecialchars($tg_user['first_name']);
  
$last_name htmlspecialchars($tg_user['last_name']);
  
$html "";
  if (isset(
$tg_user['photo_url'])) {
    
$photo_url htmlspecialchars($tg_user['photo_url']);
    
$html "<img src=\"{$photo_url}\" height=\"40px\">";
  }
  if (isset(
$tg_user['username'])) {
    
$username htmlspecialchars($tg_user['username']);
    
$html "<h2>{$html} <a href=\"https://t.me/{$username}\">{$first_name} {$last_name}</a> , 歡迎回來!</h2>";
  } else {
    
$html "<h2>{$html} {$first_name} {$last_name} , 歡迎回來!</h2>";
  }
  
$html .= "<pre align='left'>" print_r($tg_user,true) . "</pre>";
  
$html .= "<p><a href=\"?logout=1\">Log out</a></p>";

} else {
  
$bot_username BOT_USERNAME;
  
$html = <<<HTML
<h1>哈囉, 陌生人~ 請先登入喔!</h1>
<script async src="https://telegram.org/js/telegram-widget.js?2" data-telegram-login="
{$bot_username}" data-size="large" data-auth-url="i21"></script>
HTML;
}
  echo <<<HTML
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>簡單網頁對使用者進行TG登入驗證</title>
  </head>
  <body><center>
{$html}</center></body>
</html>
HTML;
?>
簡單網頁對使用者進行TG登入驗證

哈囉, 陌生人~ 請先登入喔!