Hold Tight...

0 %
Driving cybersecurity excellence
Innovator behind Kodachi OS
  • Residence:
    ::0
  • Uptime Binary:
    110001
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Cybersecurity
Programming & R&D
Cryptocurrency
AI & vibe coding
  • Bash
  • Gambas
  • Delphi
  • PHP
  • Visual Basic
  • Rust

Validating a proxy via PHP

01/05/2014
2 min readDeep Tech6 code examplesUpdated October 2026

Key points

  • Two short PHP scripts validate a proxy: the first connects through it with cURL, the second, on another node, prints the IP the request came from.
  • The original passed the ip and port from the URL straight to cURL; the PHP 7 and 8 versions check them first.
  • On Debian, Ubuntu and Kodachi OS, install php-curl (php5-curl is gone).

Updated October 2026: The idea of this 2014 post on validating a proxy still works, but the code needs changes for PHP 7 and 8:

  • php5-curl no longer exists; on Debian, Ubuntu and Kodachi OS install php-curl.
  • The original script passes the ip and port from the URL straight to cURL, so anyone can make your server connect to any address, including your own private network. I added a version under the code that validates both values first and refuses private and reserved addresses.
  • Both original code blocks also open with <php instead of <?php (the question mark was lost when the post was converted), so copy the corrected versions below them.
  • The IP echo page my script used and the demo server are retired, and E-Bouncer is now an archived project. Any page that prints the caller’s IP works, for example api.ipify.org or the small script in the second block.

This is how I use PHP and cURL to validate any proxy. Simply pass the URL with the IP and port number, and the results will be printed immediately. In PHP, we request a given URL via the proxy and check if it responds with the expected result.

First, on a Debian-based Linux box, you need to run the following command to install php-curl:

sudo apt install php-curl

cURL request code for validating a proxy

PHP
<?php
/* PHP script written by Warith AL Maawali  
# (c) 2014 Warith AL Maawali
# https://www.digi77.com
# http://www.om77.net
# script starts here:*/



//pass IP and Port via URL
$theIP=$_GET["ip"];
$thePort=$_GET["port"];
$passByIPPort= $_GET["ip"] . ":" . $_GET["port"];


// You can use any web site here to show you real ip such as http://whatismyipaddress.com/
$url = "https://www.digi77.com/software/bouncer/data/myipvv-by-web.php";

// Get current time to check proxy speed
$loadingtime = time();

$theHeader = curl_init($url);
curl_setopt($theHeader, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($theHeader, CURLOPT_TIMEOUT, 20);
curl_setopt($theHeader, CURLOPT_PROXY, $passByIPPort); 

//Execute the request
$curlResponse = curl_exec($theHeader);



if ($curlResponse === false) 
{
    echo "Proxy is not working: ", curl_error($theHeader);
} 
else 
{
    //print the output
    echo $curlResponse;
    // Get Proxy speed speed
    echo "Proxy speed: " . (time() - $loadingtime) . "s<br />\n";
}// end if



?>
PHP

For PHP 7 and 8, use this version: it restores the <?php tag, validates the ip and port before connecting, and escapes the output:

<?php
// PHP 7 and 8: check the input first, so nobody can use your server to probe other machines
$ip   = filter_input(INPUT_GET, 'ip', FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
$port = filter_input(INPUT_GET, 'port', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 65535]]);
if (!$ip || !$port) {
    exit('Invalid IP or port');
}

// Any page that prints the caller's IP address works here, for example your own script below
$url = 'https://api.ipify.org';

$start = microtime(true);
$ch = curl_init($url);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 20,
    CURLOPT_PROXY          => $ip . ':' . $port,
]);
$response = curl_exec($ch);

if ($response === false) {
    echo 'Proxy is not working: ', htmlspecialchars(curl_error($ch));
} else {
    echo 'Proxy is working, exit IP: ', htmlspecialchars($response), '<br>';
    printf('Proxy speed: %.2fs', microtime(true) - $start);
}
Download

On the other node, a small script waits for the proxy request and prints the IP address it came from.

Code to display the IP on a different node

PHP
<?php

echo  "Proxy is up and working :).<br />\n" . " The IP address we found from your request is: "  . getenv("REMOTE_ADDR") ."<br>\n" ;

?>
PHP

The corrected version for PHP 7 and 8:

<?php
// The page your checker requests through the proxy: it prints the address the request came from
header('Content-Type: text/plain');
echo 'Proxy is up and working. The IP address we found from your request is: ', $_SERVER['REMOTE_ADDR'];

The demo of this code ran at this address, which is no longer online:

http://fpnl1.digi77.com/proxychecker.php?ip=124.248.211.170&port=3128

Those were the easy steps to validate a proxy via PHP. If you are looking for an advanced multi-proxy validator, we had a free tool for that, E-Bouncer, which is now one of my archived projects.


Posted in Deep TechTags: