Since I discovered Composer for PHP the whole way of how I write code has changed. I try to use Composer as much as I can. And I always wanted to have my own packages. The first one I will present you now is filipac/ip. In a few projects that I work on often I need to get the visitor’s IP address. So I decided to make a Composer package to help me in all my projects and to help the PHP community.
How to install filipac/ip?
If you already use Composer in your project add the following code in composer.json, if not create a file called composer.json and add the following code:
"require": { "filipac/ip": "~1.0" }
After that run composer update command. I assume you already know how to use Composer, if not read here a quick start.
After that in your script you can get the visitor’s ip like that:
<?php include 'vendor/autoload.php'; use Filipac\Ip; $ip = Ip::get(); echo "Hello, your ip is {$ip}"; ?>
I hope this helps you and this plugin is useful. If you want to improve it, fork the Github project, make changes, commit and create a merge request.
Thank you.
Bun și pack ăsta! Bravo.