Last active 1727529486

prologic revised this gist 1727529486. Go to revision

1 file changed, 31 insertions

twtxt.php(file created)

@@ -0,0 +1,31 @@
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
9 + if (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
25 + if (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 + ?>
Newer Older

Powered by Opengist Load: 7ms