I\'m working on a website, and one of the things I would like to do is display MY IP address to users. The website is made with CodeIgniter, so I was looking to find my server
Try $_SERVER['SERVER_ADDR']
. It will be the IP address that the server is listening on. You can use DNS functions (e.g., gethostbyaddr()
) to get the host name.
See http://www.php.net/manual/en/reserved.variables.server.php.
If your laravel application is running on an internal server, you can use the following to get the external address of the server:
$external_ip = exec('curl http://ipecho.net/plain; echo');
for server ip address $_SERVER['SERVER_ADDR'];
and for server port $_SERVER['SERVER_PORT'];