Home > Backend Development > PHP Tutorial > 用户的登录时间和ip,怎么获取比较好?

用户的登录时间和ip,怎么获取比较好?

WBOY
Release: 2016-06-06 20:19:49
Original
1274 people have browsed it

后台用laravel框架,要记录用户的登录时间和ip,保存到mysql中,怎么获取这两个值比较好?

回复内容:

后台用laravel框架,要记录用户的登录时间和ip,保存到mysql中,怎么获取这两个值比较好?

在线预览:
https://code.levey.cn/sf_1010000004341938/

在线预览可能随时删除

<code class="php">$ip = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]; 
$ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"];
$t = date("Y-m-d H:i:s",time());
echo $ip."";
echo $t."";</code>
Copy after login

出于时间处理便利性,建议

<code class="php">$t = time();</code>
Copy after login

直接保存这个格式的时间。

在用户触发登陆事件的时候取得时间time()和_SERVER里的客户端ip

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template