Last active
August 13, 2025 08:35
-
-
Save asifulmamun/4cd3691b55d69771e9ae459765847774 to your computer and use it in GitHub Desktop.
hit_count.php - Get Hit data in hit.txt log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// hit.php - Logging + redirect + pixel image | |
$logfile = __DIR__ . '/hits.txt'; | |
// $ts_log = gmdate('Y-m-d H:i:s'); | |
$dt = new DateTime('now', new DateTimeZone('Asia/Dhaka')); | |
$ts_log = $dt->format('Y-m-d H:i:s'); | |
$ip = $_SERVER['REMOTE_ADDR'] ?? ''; | |
$ua = str_replace(["\n", "\r"], ['',''], $_SERVER['HTTP_USER_AGENT'] ?? ''); | |
$referer = $_SERVER['HTTP_REFERER'] ?? ''; | |
$uid = isset($_GET['uid']) ? preg_replace('/[^a-zA-Z0-9_\-]/', '', $_GET['uid']) : ''; | |
$extra = isset($_GET['tag']) ? preg_replace('/[^a-zA-Z0-9_\-]/', '', $_GET['tag']) : ''; | |
$isRedirected = isset($_GET['redirected']) && $_GET['redirected'] == '1'; | |
// লগের জন্য লাইন তৈরি | |
$logType = $isRedirected ? 'redirected' : 'hit'; | |
$line = implode(',', [ | |
'"' . $ts_log . '"', | |
'"' . $ip . '"', | |
'"' . $ua . '"', | |
'"' . $referer . '"', | |
'"' . $uid . '"', | |
'"' . $extra . '"', | |
'"' . $logType . '"' | |
]) . "\n"; | |
file_put_contents($logfile, $line, FILE_APPEND | LOCK_EX); | |
header('Cache-Control: no-cache, no-store, must-revalidate'); | |
header('Pragma: no-cache'); | |
header('Expires: 0'); | |
if (!$isRedirected) { | |
// প্রথমবার কল - redirect করুন পিক্সেল URL সহ ts ও redirected param | |
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; | |
$host = $_SERVER['HTTP_HOST']; | |
$scriptDir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\'); | |
$pixelPath = $scriptDir; | |
$pixelUrl = $protocol . $host . $pixelPath; | |
$ts = time(); | |
header('Location: ' . $pixelUrl . '?ts=' . $ts . '&redirected=1'); | |
exit; | |
} else { | |
// redirected কল, সরাসরি পিক্সেল ইমেজ রিটার্ন করুন | |
header('Content-Type: image/png'); | |
$png_base64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgYAAAAAMAASsJTYQAAAAASUVORK5CYII='; | |
echo base64_decode($png_base64); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment