简体   繁体   English

PHP cURL 带代理(不是 SOCKS5)

[英]PHP cURL with Proxy ( Not SOCKS5 )

I had working code that used my VPN (NordVPN) credentials through their SOCKS5 protocol.我的工作代码通过他们的 SOCKS5 协议使用了我的 VPN (NordVPN) 凭据。

Recently, they have dropped support for SOCKS5 so I have to use their other protocols, however I am unable to get any to work.最近,他们已经放弃了对 SOCKS5 的支持,所以我必须使用他们的其他协议,但是我无法让任何协议工作。

All of their available protocols can be seen here他们所有可用的协议都可以在这里看到

https://nordvpn.com/servers/tools/

- IKEv2/IPSec
- OpenVPN
- Wireguard
- HTTP Proxy (SSL)

Here is my code, attempting to use their "HTTP Proxy (SSL)" protocol这是我的代码,尝试使用他们的“HTTP 代理(SSL)”协议

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

$ch = curl_init();

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); // in seconds
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);

curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
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);
curl_close($ch);

The error I get is我得到的错误是

curl_exec(): supplied resource is not a valid cURL handle resource in ...

I don't really care what protocol it is, just need it to work.我真的不在乎它是什么协议,只需要它工作即可。

Thanks.谢谢。

After facing the same issue, I have worked out a solution遇到同样的问题后,我想出了一个解决方案

$PROXY_HOST = "xxx.xxxxxx.com";
$PROXY_PORT = "89";
$PROXY_USER = "yourproxyusername";
$PROXY_PASS = "yourproxypassword";

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PROXY_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$PROXY_USER:$PROXY_PASS");
curl_setopt($ch, CURLOPT_PROXY, "https://$PROXY_HOST:$PROXY_PORT");


curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response= curl_exec($ch);
$error = curl_error($ch); 
echo $error;
echo $response;
curl_close($ch);

One thing to note is that for NordVPN you have to use the port 89 for HTTP Proxy (SSL) and the username and password is not your account username and password, but your proxy specific credentials that you can find on your account page.需要注意的一点是,对于 NordVPN,您必须将端口 89 用于 HTTP 代理 (SSL),并且用户名和密码不是您的帐户用户名和密码,而是您可以在帐户页面上找到的代理特定凭据。

Also dont quote me on this, but I think you need to use PHP 7.3+ for this to work.也不要引用我的话,但我认为你需要使用 PHP 7.3+ 才能工作。

we can use it with protonvpn or vpnbook?我们可以将它与 protonvpn 或 vpnbook 一起使用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM