Support Forums
[Function] Test HTTP/Socks 4/Socks 5 Proxy - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: [Function] Test HTTP/Socks 4/Socks 5 Proxy (/showthread.php?tid=4940)



[Function] Test HTTP/Socks 4/Socks 5 Proxy - OX!DE - 02-21-2010

A quick function using cURL to identify if a certain proxy server is currently working/accepting connections, returns true if it is.

PHP Code:
<?php
// Live Demo: http://x32.bz/tools/proxychecker/
// Example Usage: checkproxy("222.124.223.42","3128","SOCKS 5");
function checkproxy($ip,$port,$type){
$ch curl_init("127.0.0.1");
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_CONNECTTIMEOUT10);
curl_setopt($chCURLOPT_TIMEOUT10);
curl_setopt($chCURLOPT_PROXY$ip ":" $port);
if(
$type == "SOCKS 4"curl_setopt($chCURLOPT_PROXYTYPECURLPROXY_SOCKS4);
else if(
$type == "SOCKS 5"curl_setopt($chCURLOPT_PROXYTYPECURLPROXY_SOCKS5);
$html curl_exec($ch);
$info curl_getinfo($ch);
if(
curl_errno($ch) || $html == "") {
return 
FALSE;
}else{
return 
TRUE;
}
curl_close($ch);