You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NordVPN取消SOCKS5支持后PHP cURL代理配置问题求助

Fixing Your NordVPN Proxy Issue in PHP

Hey there, let's get your code working again. First, let's address the immediate error you're seeing with the HTTP Proxy (SSL) setup, then we'll cover other reliable protocol options like WireGuard that NordVPN supports.

Fixing the HTTP Proxy (SSL) Code

The error curl_exec(): supplied resource is not a valid cURL handle resource is almost certainly caused by an invalid value for CURLOPT_PROXYTYPE. You used the string 'HTTP', but cURL requires its predefined constants here. For an HTTPS-enabled HTTP proxy, you need CURLPROXY_HTTPS.

Here's the corrected code with additional error checking to help diagnose future issues:

<?php
// Ensure these variables are properly set with your credentials and target URL
$agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36';
$proxyUser = 'your_nordvpn_username';
$proxyPass = 'your_nordvpn_password';
$Url = 'https://example.com'; // Replace with your target URL

$cookie_file = tempnam("/tmp", "CURLCOOKIE");
$ch = curl_init();

// Check if curl initialization succeeded
if (!$ch) {
    die('Failed to initialize cURL: ' . curl_error());
}

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Note: Disable this in production if you can use valid CA certificates
// Fix: Use the correct cURL constant for HTTPS proxy
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);
curl_setopt($ch, CURLOPT_PROXYPORT, 443);
curl_setopt($ch, CURLOPT_PROXY, "au643.nordvpn.com");
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyUser . ":" . $proxyPass);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_URL, $Url);

$result = curl_exec($ch);

// Check for execution errors
if ($result === false) {
    echo 'cURL execution failed: ' . curl_error($ch);
} else {
    echo $result;
}

curl_close($ch);
unlink($cookie_file); // Clean up the temporary cookie file
?>

Key Fixes:

  • Replaced 'HTTP' with CURLPROXY_HTTPS for CURLOPT_PROXYTYPE
  • Added checks for curl_init() and curl_exec() failures to surface specific errors
  • Added cleanup for the temporary cookie file

If the HTTP proxy still gives you trouble, WireGuard is a lightweight, fast protocol that NordVPN fully supports. This method requires WireGuard installed on your system and a NordVPN WireGuard config file (you can get this via NordVPN's internal tools).

Here's a PHP example that starts a WireGuard connection, runs your cURL request, then cleans up:

<?php
// Ensure you have your NordVPN WireGuard config saved at /etc/wireguard/nordvpn.conf
// Start WireGuard connection (may require sudo privileges)
exec('wg-quick up nordvpn.conf', $output, $return_var);
if ($return_var !== 0) {
    die('Failed to start WireGuard connection: ' . implode("\n", $output));
}

// Now cURL will route traffic through WireGuard
$ch = curl_init('https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

if ($result === false) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    echo $result;
}

curl_close($ch);

// Stop the WireGuard connection when done
exec('wg-quick down nordvpn.conf');
?>

Notes for WireGuard:

  • You may need to configure sudoers to allow your PHP user to run wg-quick without a password
  • WireGuard generally offers better performance than HTTP proxies or OpenVPN

Alternative: OpenVPN

Similar to WireGuard, you can use OpenVPN by starting a system-level connection. You'll need an OpenVPN config file from NordVPN and the OpenVPN client installed:

<?php
// Start OpenVPN connection (adjust the config path as needed)
exec('openvpn --config /path/to/nordvpn_openvpn.conf --daemon', $output, $return_var);
if ($return_var !== 0) {
    die('Failed to start OpenVPN: ' . implode("\n", $output));
}

// Add a small delay to let the connection establish
sleep(10);

// Run your cURL request
$ch = curl_init('https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

if ($result === false) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    echo $result;
}

curl_close($ch);

// Stop OpenVPN
exec('pkill openvpn');
?>

Pick the method that works best for your environment—start with the corrected HTTP proxy code since it requires no system-level setup, then move to WireGuard if you need better performance.

内容的提问来源于stack exchange,提问作者nomaam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:48:13