laravel 4 saving ip address to model

后端 未结 3 990
一个人的身影
一个人的身影 2020-12-28 19:11

I\'m trying to save a user ip address to my database using Laravel 4. I found the following function which returns a string

Request::getClientIp()
         


        
3条回答
  •  抹茶落季
    2020-12-28 19:30

    From @Unnawut.

    You need to change from binary(16) to varbinary(16) if you want to deal with both ipv4 and ipv6 in the same field.

    But if you need to deal only ip v4 just INT UNSIGNED

    If you want to deal only ip v6 BINARY(16)

    ref: MYSQL - SELECT IP v4/v6, inet_pton & bin2hex

    ref2: https://stackoverflow.com/a/5133610/2126472

提交回复
热议问题