The aim of this guide is to demonstrate how to import IP2Proxy data in CSV form into Redis and then query the data in a PHP web page.
First of all, you will need to download the IP2Proxy CSV file. You can use any of the PX packages from PX1 to PX10.
Download Free LITE version at https://lite.ip2location.com/
Download commercial version at https://www.ip2location.com/download
Extract out the file from the downloaded zipped file.
We will not cover installation of Redis, Perl or PHP in this guide. We will assume you have already setup Redis on the localhost and are using PHP via Apache (also on the localhost). For this example, we are using a Debian Linux.
More info can be found at the following URLs if you need assistance with installations:
Perl Redis Library: http://search.cpan.org/~dams/Redis/lib/Redis.pm
PHP Redis Library: http://pecl.php.net/package/redis
We will be using the Perl Redis library to do mass import of CSV data into Redis and then querying the data via PHP using the PHP Redis library.
Importing the CSV data into Redis
As mentioned earlier, we will be using a Perl script to perform the import of the CSV data into Redis as we need to format our CSV data into an easier to store form.
Create a new Perl file called importredis.pl and paste the following code into it:
Run the Perl script by calling the below command in command prompt:
Querying the IP2Proxy data from a PHP web page
Now, create a PHP file called test.php in your website.
Paste the following PHP code into it and then run it in the browser: