Last active 1727529486

Revision 29e29bb3b31484acafe769c62cf779c1c4f83f45

twtxt.php Raw
1<?php
2// Path to the text file to be served
3$textFile = 'your-text-file.txt';
4
5// Path to the log file where User-Agents will be saved
6$logFile = 'user_agents.log';
7
8// Serve the text file content
9if (file_exists($textFile)) {
10 // Set appropriate headers to serve a plain text file
11 header('Content-Type: text/plain');
12 header('Content-Disposition: inline; filename="' . basename($textFile) . '"');
13 header('Content-Length: ' . filesize($textFile));
14
15 // Output the text file
16 readfile($textFile);
17} else {
18 // If the file doesn't exist, return a 404 response
19 header("HTTP/1.0 404 Not Found");
20 echo "File not found.";
21 exit;
22}
23
24// Parse the HTTP request headers to get the User-Agent
25if (isset($_SERVER['HTTP_USER_AGENT'])) {
26 $userAgent = $_SERVER['HTTP_USER_AGENT'];
27
28 // Open the log file for appending and write the User-Agent
29 file_put_contents($logFile, $userAgent . PHP_EOL, FILE_APPEND | LOCK_EX);
30}
31?>
32

Powered by Opengist Load: 7ms