gpt4 book ai didi

javascript - 如何统计用户的点击URL?

转载 作者:行者123 更新时间:2023-12-03 11:17:35 26 4
gpt4 key购买 nike

while($rows=mysql_fetch_assoc($run)) {

$title=$rows['title'];
$desc=$rows['description'];
$url=$rows['url'];
//include 'index.php';
echo "<a href='$url'><b>$title</b></a><br><a href='$url'>$url"</a><p>";
}

这部分不同$url会在屏幕上显示给用户,用户可以点击任意url来显示数据。我想统计哪个url点击了多少次来给出页面排名?

最佳答案

使用中介文件而不是直接链接到 URL

中介 PHP 文件将计算它被调用的次数(使用计数器),然后重定向到实际的 URL

<a href="redirect.php?redirect=http://domain.com>URL</a>

根据您的代码,它应该类似于

while($rows=mysql_fetch_assoc($run)) {

$title=$rows['title'];
$desc=$rows['description'];
$url=urlencode($rows['url']);
//include 'index.php';
echo "<a href='redirect.php?$url'><b>$title</b></a><br><a href='$url'>$url"</a><p>";
}

并在您的redirect.php文件中(计数和重定向文件)

if(!file_exists('counter.txt')){ 
file_put_contents('counter.txt', '0');
}
file_put_contents('counter.txt', ((int) file_get_contents('counter.txt')) + 1);
header('Location: ' . $_GET['redirect']);

关于javascript - 如何统计用户的点击URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27265024/

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