利用 QQ 空間編輯器的 Referer 機制,結合公開的 QQ 資料介面,動態生成包含當前訪客 QQ 號與暱稱的圖片。常見於 QQ 空間轉發圖片、個性化歡迎圖等場景。
$_SERVER['HTTP_REFERER'] 取得來源頁面 URLhttps://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?uin=QQ號 獲取 JSON 資料nickname 欄位<?php
$ment = $_SERVER["HTTP_REFERER"];
if ($ment == 'https://cnc.qzs.qq.com/qzone/newblog/v5/editor.html') {
header("HTTP/1.0 500 Internal Server Error");
exit;
}
preg_match("#[0-9]{5,11}#", $ment, $rr);
$r = $rr[0];
$webtext = file_get_contents('https://www.phperzone.cn/demo/qqinfo-service.php?qq=' . $r);
preg_match('#"nickname":"(.*?)"#', $webtext, $rr);
$rrr = $rr[1];
ob_clean();
header("Content-type: image/png");
$im = imagecreatefromjpeg("1.jpg");
$black = ImageColorAllocate($im, 56, 73, 136);
$rrr = mb_convert_encoding($rrr, "utf-8", "UTF-8");
imagettftext($im, 20, 0, 90, 68, $black, "./simsun.ttc", $rrr);
imagettftext($im, 26, 0, 87, 125, $black, "./simsun.ttc", $r);
imagejpeg($im);
imagedestroy($im);
?>
<?php
header("Content-Type: text/html; charset=utf-8");
$qq = $_GET["qq"];
echo htmlspecialchars(file_get_contents('https://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?uin=' . $qq));
?>
1.jpg 與字型檔 simsun.ttc(需授權或使用開源字型)allow_url_fopen 或使用 cURL 替代獲取並展示他人 QQ 暱稱屬於個人資訊處理,請遵守相關隱私法規與騰訊服務條款,勿用於商業追蹤或騷擾。
此技術展示 HTTP Referer、公開 API 串接與 GD 圖片生成的綜合應用。