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

标签 javascript php html

我有一个网站,我想跟踪访问该网站的所有用户代理。并将所有用户代理保存在文件中,或通过电子邮件发送。我如何在 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/

相关文章:

javascript - 设置选定的选项 JQuery

javascript - 当我打开太多页面并忽略最后一个 URL 时,PhantomJS 崩溃

javascript - HTML Div 和建议

php - 将 cURL Cookie 复制给访问用户(使用 Javascript?)

javascript - 如何在 bookshelf.js 中设置我的数据库模型

php - codeigniter html电子邮件更改字符

php - 我需要哪个选项来使用 HHVM 编译 php 代码

php - 点击 'home' -logo 返回 404 错误页面

javascript - jQuery find next 不适用于 div 结构

html - Razor Pages DateTime 输入大小错误