Laravel-获取网站唯一身份访问者人数 [英] Laravel - Get website unique visitor count

查看:68
本文介绍了Laravel-获取网站唯一身份访问者人数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上收集唯一数量的访问者并将其存储在数据库中.即使没有帐户的人访问该网站,访问者数量也会上升.我该怎么做?

I want to collect the unique amount of visitors on my website and store them in a database. Even when someone without an account accesses the website the visitor count goes up. How can I accomplish this?

我知道我必须按照这些原则获取用户的IP地址或其他内容,但是我不知道如何在页面加载时获取没有帐户的用户的IP地址

I know I have to fetch the users IP address or something along those lines but I don't know how to fetch the IP address of a user without an account when the page loads

当前我有此数据库表

Visitors
 - ip
 - date_visited

路线

Route::get('/', function () {
    $ip = Request::ip();
    return view('welcome', compact('ip'));
});

推荐答案

尝试使用 Request :: ip()获取IP;

$ip = Request::ip();

对于Laravel 5.4 +:

For Laravel 5.4 +:

$ip = $request->ip();
// or
$ip = request()->ip();

我认为您可以使用中间件 redis 来计算此计数,这将减少数据库的压力.

And I think you can use middleware and redis to calculate this count, this will reduce the db's pressure.

这篇关于Laravel-获取网站唯一身份访问者人数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆