gpt4 book ai didi

javascript - 跟踪访问站点的用户代理

转载 作者:行者123 更新时间:2023-12-03 05:45:58 24 4
gpt4 key购买 nike

我有一个网站,我想跟踪访问该网站的所有用户代理。并将所有用户代理保存在文件中,或通过电子邮件发送。我如何在 PHP 或 JS 中实现这一点?

最佳答案

好的,需要发生三件事。写入文件,邮寄内容,邮寄后清除文件。第一部分将在一个单独的文件中,而邮件和文件清除将在另一个文件中

<?php

// get the user agent
$user_agent = $_SERVER['HTTP_USER_AGENT'];

// write to file
file_put_contents( 'user_agents.log', $user_agent, FILE_APPEND );

?>

<?php


// fetch the list of user agents from the file
$body = file_get_contents( 'user_agents.log' );

// mail to whereva
mail( 'admin@example.com', 'User Agent Log', $body );

// truncate the file back to zero
$fh = fopen( 'user_agents.log', 'w' );
fclose($fh);
?>

关于javascript - 跟踪访问站点的用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40334058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com