How to Detect a VPN with PHP for Free

 

How to Detect a VPN with PHP for Free
How to Detect a VPN with PHP for Free


How to Detect a VPN with PHP for Free

In this article, we will be providing you an example in detecting either a VPN, proxy, or TOR Exit Node using PHP alongside with our VPN API.

With this code, you can get a general idea on how to implement our VPN detection API within your PHP application. The PHP script has two options that allows you to either automatically obtain the client’s IP Address or by manually inputting an IP Address by commenting out the $IP_ADDRESS = $_SERVER[‘REMOTE_ADDR’]; line.

However, our VPN detection API does require an API key, which can be easily obtainable by simply creating a VPNAPI.io account. Our API keys are free, with a limitation of 1000 requests per a day. Though, that limitation can easily be removed if you were to purchase an API plan.

PHP Code for detecting a VPN:



// Make Content Type into Text
header('Content-type: text/plain');

// Get IP Address
$IP_ADDRESS = '127.0.0.1'; # Manual IP Address
$IP_ADDRESS = '127.0.0.1'; # Manual IP Address
$IP_ADDRESS = "191.96.97.58"; //VPN
$IP_ADDRESS = "190.8.35.226"; // proxy
$IP_ADDRESS = "118.89.176.33"; // VPN and proxy
$IP_ADDRESS = "103.160.137.9"; // No VPN and proxy
$IP_ADDRESS = $_SERVER['REMOTE_ADDR']; # Automatically get IP Address // Input VPNAPI.IO API Key // Create an account to get a free API Key // Free API keys has a limit of 1000/requests per a day $API_KEY = "API_KEY_GOES_HERE"; // API URL $API_URL = 'https://vpnapi.io/api/' . $IP_ADDRESS . '?key=' . $API_KEY; // Fetch VPNAPI.IO API $response = file_get_contents($API_URL); // Decode JSON response $response = json_decode($response); // Check if IP Address is VPN if($response->security->vpn) { // Add code here for any IP Address that is a VPN echo $IP_ADDRESS, " is a VPN.\n"; } else { // Add code here for any IP Address that is not a VPN echo $IP_ADDRESS, " is not a VPN.\n"; } // Check if IP Address is Proxy if($response->security->vpn) { // Add code here for any IP Address that is a proxy echo $IP_ADDRESS, " is a proxy.\n"; } else { // Add code here for any IP Address that is not a proxy echo $IP_ADDRESS, " is not a proxy.\n"; } // Check if IP Address is TOR Exit Node if($response->security->vpn) { // Add code here for any IP Address that is a TOR Node echo $IP_ADDRESS, " is a TOR Node.\n"; } else { // Add code here for any IP Address that is not a TOR Node echo $IP_ADDRESS, " is not a TOR Node.\n"; }




Method  2


$IP_ADDRESS = "191.96.97.58";
$IP_ADDRESS = "103.160.137.9";
$IP_ADDRESS = "127.0.0.1";
$IP_ADDRESS = $_SERVER['REMOTE_ADDR']; # Automatically get IP Address
$IP_ADDRESS = "1.2.1.99";
$API_URL = 'https://proxycheck.io/v2/'. $IP_ADDRESS .'?key='.$API_KEY.'&risk=1&vpn=1';

// Fetch VPNAPI.IO API
$response = file_get_contents($API_URL);
// Decode JSON response
$response = json_decode($response);

// return view('index');
if($response->status == "error"){
return $response->message;
} else {
return $response->$IP_ADDRESS->proxy;

}



Post a Comment

أحدث أقدم