twtxt.php
Raw
<?php
// Path to the text file to be served
$textFile = 'your-text-file.txt';
// Path to the log file where User-Agents will be saved
$logFile = 'user_agents.log';
// Serve the text file content
if (file_exists($textFile)) {
// Set appropriate headers to serve a plain text file
header('Content-Type: text/plain');
header('Content-Disposition: inline; filename="' . basename($textFile) . '"');
header('Content-Length: ' . filesize($textFile));
// Output the text file
readfile($textFile);
} else {
// If the file doesn't exist, return a 404 response
header("HTTP/1.0 404 Not Found");
echo "File not found.";
exit;
}
// Parse the HTTP request headers to get the User-Agent
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$userAgent = $_SERVER['HTTP_USER_AGENT'];
// Open the log file for appending and write the User-Agent
file_put_contents($logFile, $userAgent . PHP_EOL, FILE_APPEND | LOCK_EX);
}
?>
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 | ?> |
32 |