After purchasing static IP services from IPNut platform, use the following PHP code samples for integration.
1. SOCKS5 Proxy Implementation Socks5ProxyDemo.php #
'https://httpbin.org/ip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-PHP-SOCKS5/1.0',
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
throw new Exception('cURL Error: ' . curl_error($ch));
}
echo "Status Code: " . $httpCode . "\n";
echo "Response: " . $response . "\n";
echo "✅ SOCKS5 Proxy test completed successfully\n";
} catch (Exception $e) {
echo "❌ Request failed: " . $e->getMessage() . "\n";
} finally {
curl_close($ch);
}
}
/**
* Multiple requests through SOCKS5 proxy
*/
public function socks5MultipleRequests() {
echo "\n=== SOCKS5 Multiple Requests ===\n";
$urls = [
'https://httpbin.org/ip',
'https://httpbin.org/user-agent',
'https://httpbin.org/headers'
];
foreach ($urls as $index => $url) {
echo "\nRequest " . ($index + 1) . ": " . $url . "\n";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-PHP-Multi/1.0',
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
echo "❌ Request failed: " . curl_error($ch) . "\n";
} else {
echo "✅ Status Code: " . $httpCode . "\n";
$data = json_decode($response, true);
echo "Response Preview: " . substr($response, 0, 120) . "...\n";
}
curl_close($ch);
sleep(1); // Rate limiting
}
}
/**
* SOCKS5 Proxy with custom POST request
*/
public function socks5CustomRequest() {
echo "\n=== SOCKS5 Custom POST Request ===\n";
$ch = curl_init();
try {
$headers = [
'User-Agent: IPNut-PHP-Custom/1.0',
'Accept: application/json',
'Content-Type: application/json',
'X-Proxy-Type: SOCKS5'
];
$postData = [
'service' => 'IPNut Proxy',
'protocol' => 'SOCKS5',
'timestamp' => date('c'),
'test_id' => uniqid()
];
curl_setopt_array($ch, [
CURLOPT_URL => 'https://httpbin.org/post',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($postData),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
throw new Exception('cURL Error: ' . curl_error($ch));
}
echo "✅ Status Code: " . $httpCode . "\n";
$result = json_decode($response, true);
echo "POST Response Data:\n";
print_r($result['json'] ?? $result);
} catch (Exception $e) {
echo "❌ POST request failed: " . $e->getMessage() . "\n";
} finally {
curl_close($ch);
}
}
/**
* Advanced SOCKS5 configuration with error handling
*/
public function socks5Advanced() {
echo "\n=== SOCKS5 Advanced Configuration ===\n";
$ch = curl_init();
try {
curl_setopt_array($ch, [
CURLOPT_URL => 'https://httpbin.org/anything',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-Advanced-Client/1.0',
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'X-Client: IPNut-PHP',
'X-Request-ID: ' . uniqid()
],
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$totalTime = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
if (curl_error($ch)) {
throw new Exception('cURL Error: ' . curl_error($ch));
}
echo "✅ Request completed successfully\n";
echo "Status Code: " . $httpCode . "\n";
echo "Total Time: " . round($totalTime, 2) . "s\n";
echo "Response Size: " . strlen($response) . " bytes\n";
} catch (Exception $e) {
echo "❌ Advanced request failed: " . $e->getMessage() . "\n";
} finally {
curl_close($ch);
}
}
/**
* Run all SOCKS5 demonstrations
*/
public function runAll() {
echo "Starting IPNut SOCKS5 Proxy Tests...\n\n";
$this->socks5WithCurl();
$this->socks5MultipleRequests();
$this->socks5CustomRequest();
$this->socks5Advanced();
echo "\n✅ All SOCKS5 proxy tests completed!\n";
}
}
// Run SOCKS5 demo if executed directly
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
$socks5Demo = new Socks5ProxyDemo();
$socks5Demo->runAll();
}
?>
2. HTTP Proxy Implementation HttpProxyDemo.php #
'https://httpbin.org/ip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_PROXYAUTH => CURLAUTH_BASIC,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-PHP-HTTP/1.0',
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
throw new Exception('cURL Error: ' . curl_error($ch));
}
echo "Status Code: " . $httpCode . "\n";
echo "Response: " . $response . "\n";
echo "✅ HTTP Proxy test completed successfully\n";
} catch (Exception $e) {
echo "❌ Request failed: " . $e->getMessage() . "\n";
} finally {
curl_close($ch);
}
}
/**
* HTTP Proxy using stream context
*/
public function httpWithStream() {
echo "\n=== HTTP Proxy with Stream Context ===\n";
try {
$context = stream_context_create([
'http' => [
'proxy' => 'tcp://' . $this->proxy_host . ':' . $this->proxy_port,
'request_fulluri' => true,
'header' => [
'Proxy-Authorization: Basic ' . base64_encode($this->proxy_username . ':' . $this->proxy_password),
'User-Agent: IPNut-Stream-Client/1.0',
'Accept: application/json'
],
'timeout' => 30,
'follow_location' => 1
],
'ssl' => [
'verify_peer' => true,
'verify_peer_name' => true,
'allow_self_signed' => false
]
]);
$response = file_get_contents('https://httpbin.org/ip', false, $context);
if ($response === false) {
throw new Exception('Stream request failed');
}
$statusLine = $http_response_header[0] ?? '';
preg_match('/HTTP\/\d\.\d\s+(\d+)/', $statusLine, $matches);
$httpCode = $matches[1] ?? 'Unknown';
echo "✅ Status Code: " . $httpCode . "\n";
echo "Response: " . $response . "\n";
} catch (Exception $e) {
echo "❌ Stream request failed: " . $e->getMessage() . "\n";
}
}
/**
* HTTP Proxy with concurrent requests
*/
public function httpMultipleRequests() {
echo "\n=== HTTP Proxy Concurrent Requests ===\n";
$urls = [
'https://httpbin.org/ip',
'https://httpbin.org/user-agent',
'https://httpbin.org/headers',
'https://httpbin.org/get?test=ipnut_proxy'
];
$multiHandle = curl_multi_init();
$handles = [];
foreach ($urls as $index => $url) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-Concurrent/1.0',
CURLOPT_SSL_VERIFYPEER => true
]);
curl_multi_add_handle($multiHandle, $ch);
$handles[$index] = ['ch' => $ch, 'url' => $url];
}
// Execute concurrent requests
$running = null;
do {
curl_multi_exec($multiHandle, $running);
curl_multi_select($multiHandle);
} while ($running > 0);
// Process results
foreach ($handles as $index => $handle) {
echo "\nRequest " . ($index + 1) . ": " . $handle['url'] . "\n";
$response = curl_multi_getcontent($handle['ch']);
$httpCode = curl_getinfo($handle['ch'], CURLINFO_HTTP_CODE);
if (curl_error($handle['ch'])) {
echo "❌ Request failed: " . curl_error($handle['ch']) . "\n";
} else {
echo "✅ Status Code: " . $httpCode . "\n";
echo "Response Preview: " . substr($response, 0, 100) . "...\n";
}
curl_multi_remove_handle($multiHandle, $handle['ch']);
curl_close($handle['ch']);
}
curl_multi_close($multiHandle);
}
/**
* HTTP Proxy POST with JSON data
*/
public function httpPostRequest() {
echo "\n=== HTTP Proxy POST Request ===\n";
$ch = curl_init();
try {
$postData = [
'service' => 'IPNut HTTP Proxy',
'protocol' => 'HTTP',
'authentication' => 'basic',
'timestamp' => date('c'),
'test_data' => [
'feature' => 'static_ip',
'stability' => 'high',
'anonymity' => 'enterprise'
]
];
$headers = [
'Content-Type: application/json',
'User-Agent: IPNut-PHP-POST/1.0',
'X-API-Version: 1.0'
];
curl_setopt_array($ch, [
CURLOPT_URL => 'https://httpbin.org/post',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($postData),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
throw new Exception('cURL Error: ' . curl_error($ch));
}
echo "✅ Status Code: " . $httpCode . "\n";
$result = json_decode($response, true);
echo "POST Response Summary:\n";
echo " - Headers Sent: " . count($result['headers'] ?? []) . "\n";
echo " - Data Received: " . strlen($response) . " bytes\n";
echo " - Origin IP: " . ($result['origin'] ?? 'Unknown') . "\n";
} catch (Exception $e) {
echo "❌ POST request failed: " . $e->getMessage() . "\n";
} finally {
curl_close($ch);
}
}
/**
* Run all HTTP demonstrations
*/
public function runAll() {
echo "Starting IPNut HTTP Proxy Tests...\n\n";
$this->httpWithCurl();
$this->httpWithStream();
$this->httpMultipleRequests();
$this->httpPostRequest();
echo "\n✅ All HTTP proxy tests completed!\n";
}
}
// Run HTTP demo if executed directly
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
$httpDemo = new HttpProxyDemo();
$httpDemo->runAll();
}
?>
3. Connectivity Testing Utility ProxyTestTool.php #
'https://httpbin.org/ip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-Test-Client/1.0',
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$connectTime = curl_getinfo($ch, CURLINFO_CONNECT_TIME);
if (curl_error($ch)) {
echo "❌ SOCKS5 Proxy Connection Failed: " . curl_error($ch) . "\n";
} else {
echo "✅ SOCKS5 Proxy Connection Successful\n";
echo " Status Code: " . $httpCode . "\n";
echo " Connect Time: " . round($connectTime, 2) . "s\n";
$data = json_decode($response, true);
echo " Assigned IP: " . ($data['origin'] ?? 'Unknown') . "\n";
}
curl_close($ch);
}
/**
* Test HTTP proxy connectivity
*/
public function testHttpProxy() {
echo "\nTesting HTTP Proxy Connectivity:\n";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://httpbin.org/ip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_USERAGENT => 'IPNut-Test-Client/1.0',
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$connectTime = curl_getinfo($ch, CURLINFO_CONNECT_TIME);
if (curl_error($ch)) {
echo "❌ HTTP Proxy Connection Failed: " . curl_error($ch) . "\n";
} else {
echo "✅ HTTP Proxy Connection Successful\n";
echo " Status Code: " . $httpCode . "\n";
echo " Connect Time: " . round($connectTime, 2) . "s\n";
$data = json_decode($response, true);
echo " Assigned IP: " . ($data['origin'] ?? 'Unknown') . "\n";
}
curl_close($ch);
}
/**
* Comprehensive proxy testing
*/
public function comprehensiveTest() {
echo "\n=== Comprehensive Proxy Test ===\n";
$testUrls = [
'https://httpbin.org/ip',
'https://httpbin.org/user-agent',
'https://httpbin.org/headers'
];
$proxyTypes = [
'SOCKS5' => CURLPROXY_SOCKS5,
'HTTP' => CURLPROXY_HTTP
];
foreach ($proxyTypes as $proxyName => $proxyType) {
echo "\nTesting " . $proxyName . " Proxy:\n";
foreach ($testUrls as $testUrl) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $testUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_PROXY => $this->proxy_host . ':' . $this->proxy_port,
CURLOPT_PROXYTYPE => $proxyType,
CURLOPT_PROXYUSERPWD => $this->proxy_username . ':' . $this->proxy_password,
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$success = !curl_error($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200;
if ($success) {
echo " ✅ " . $testUrl . " - Success\n";
} else {
echo " ❌ " . $testUrl . " - Failed: " . curl_error($ch) . "\n";
}
curl_close($ch);
}
}
}
/**
* Run all tests
*/
public function runTests() {
echo "=== IPNut Proxy Connectivity Test ===\n\n";
$this->testSocks5Proxy();
$this->testHttpProxy();
$this->comprehensiveTest();
echo "\n✅ All proxy connectivity tests completed!\n";
}
}
// Run test tool if executed directly
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
$testTool = new ProxyTestTool();
$testTool->runTests();
}
?>
4. Main Program Entry Point main.php #
runTests();
echo "\n" . str_repeat("=", 60) . "\n\n";
// Run SOCKS5 proxy demonstrations
$socks5Demo = new Socks5ProxyDemo();
$socks5Demo->runAll();
echo "\n" . str_repeat("=", 60) . "\n\n";
// Run HTTP proxy demonstrations
$httpDemo = new HttpProxyDemo();
$httpDemo->runAll();
echo "\n" . str_repeat("=", 60) . "\n";
echo "🎉 All IPNut proxy integration demonstrations completed successfully!\n";
}
}
// Run main program
$main = new MainProgram();
$main->run();
?>
5. Execution Commands #
#文件结构:
# proxy_demo/
# ├── Socks5ProxyDemo.php # SOCKS5 Proxy Implementation
# ├── HttpProxyDemo.php # HTTP Proxy Implementation
# ├── ProxyTestTool.php # Connectivity Testing
# └── main.php # Main Entry Point
# Navigate to project directory
cd proxy_demo
# 1. Run SOCKS5 demo only
php Socks5ProxyDemo.php
# 2. Run HTTP demo only
php HttpProxyDemo.php
# 3. Run connectivity tests only
php ProxyTestTool.php
# 4. Run complete demonstration
php main.php
Key Integration Notes:
PHP Requirements: cURL extension must be enabled
Security: Enable SSL verification in production environments
Error Handling: Comprehensive exception handling included
Performance: Connection timeouts and rate limiting implemented
Credential Management: Replace example credentials with actual IPNut proxy details
Best Practices:
Resource Management: Always close cURL handles
Error Handling: Check for cURL errors and HTTP status codes
Performance: Use concurrent requests for multiple operations
Security: Validate SSL certificates in production
Technical Support
For integration assistance or location-specific requirements:
Email: Support@ipnut.com
Live Chat: 24/7 real-time support via official website
*All code examples support both HTTP and SOCKS5 protocols with enterprise-grade authentication and security features.*