Yii2 ip based login
<p>I am trying to create a login with an username a password several roles and an ip verification, where when the user doesn't have an assigned ip he can't login. I'm saving my ip as a varchar in my user table and I'm trying to compare the ip on the table with the one of the user that's trying to login, but when I login it returns me this ip ::1 which is the ipv6 from localhost as I have read and in my db I have 127.0.0.1 (I have tried doing it with ::1 on the db but no success) my question is:</p>
<p>What should I do to get a correct response? here is my code</p>
<pre><code>    public function validateIp($ip) {
    if($this-&gt;ip == Yii::$app-&gt;request-&gt;userIp)
    {
       return $this-&gt;ip == $ip;                   
    }
        else
        {
            $this-&gt;addError($ip, 'La IP no esta habilitada para este usuario');
        }
    
}
</code></pre>
<p>And here I execute the login</p>
<pre><code>   public function login()  
   {
      if ($this-&gt;validateIp(Yii::$app-&gt;request-&gt;userIp)) 
      {
         if ($this-&gt;validate()) 
         {
           return Yii::$app-&gt;user-&gt;login($this-&gt;getUser());
         }
      }
   }
</code></pre>