Yii中获取用户IP地址的函数 [英] function to get user IP address in Yii
本文介绍了Yii中获取用户IP地址的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个获取用户 IP 地址的快捷方式,我在下面的 protected/helpers/shortcut.php
I'm trying to create a s shortcut to get user IP address, I created this function below in protected/helpers/shortcut.php
echo getIP();
function getIP()
{
return CHttpRequest::getUserHostAddress();
}
我收到此错误是因为我将 php.ini 设置为严格.并且 getUserHostAddress() 不是静态函数
i get this error because i set my php.ini to strict. and getUserHostAddress() is not a static function
Strict Standards: Non-static method CHttpRequest::getUserHostAddress() should not be called statically in /Applications/XAMPP/xamppfiles/htdocs/dev/protected/helpers/shortcuts.php on line 97
::1
我试过了
Yii::app()->request->userHostAddress;
但我收到此错误
Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/dev/protected/helpers/shortcuts.php on line 97
知道我做错了什么吗?谢谢
any idea what i'm doing wrong? Thanks
推荐答案
试试这个:
Yii::app()->request->getUserHostAddress()
代替
Yii::app()->request->getUserHostAddress
使用()"应该可以工作
with "()" it should work
这篇关于Yii中获取用户IP地址的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文