function to get user IP address in Yii

前端 未结 2 361
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 11:44

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();
fun         


        
相关标签:
2条回答
  • 2021-01-11 12:03

    In Yii2, use Yii::$app->getRequest()->getUserIP()

    0 讨论(0)
  • 2021-01-11 12:18

    try this:

    Yii::app()->request->getUserHostAddress()
    

    instead

    Yii::app()->request->getUserHostAddress
    

    with "()" it should work

    0 讨论(0)
提交回复
热议问题