Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Play Framework getting user's ip address

I have seen this asked before, but I haven't been able to use those answers to get the IP address of the user.

in PHP it would be this:

$_SERVER['REMOTE_ADDR'];
like image 210
user1704877 Avatar asked Sep 27 '12 23:09

user1704877


1 Answers

If you need to access this information within an action:

Action { request =>
    val address = request.remoteAddress;
    ...
}

If you need the access somewhere else, note that you can use implicit:

Action { implicit request => ... }
myMethod(implicit request: Request) { ... }

And you can always fall back to just passing the request around.

like image 193
Mirko Adari Avatar answered Oct 02 '22 20:10

Mirko Adari