简体   繁体   English

如何在 php-curl 中使用 CURLOPT_LOGIN_OPTIONS?

[英]How to use CURLOPT_LOGIN_OPTIONS in php-curl?

curl have a CURLOPT_LOGIN_OPTIONS parameter ( --login-options in terminal app). curl 有一个CURLOPT_LOGIN_OPTIONS参数(终端应用程序中的 --login-options )。 How to use it in php script with php5-curl?如何在带有 php5-curl 的 php 脚本中使用它? By default, it has no CURLOPT_LOGIN_OPTIONS and use code like curl_setopt($ch, 12345, "auth=PLAIN");默认情况下,它没有 CURLOPT_LOGIN_OPTIONS 并使用像 curl_setopt($ch, 12345, "auth=PLAIN"); 这样的代码。 doesn't change lead to curl behavioral change.不改变导致卷曲行为改变。 I won't use exec in my code.我不会在我的代码中使用 exec 。 Thanks.谢谢。

In PHP if you want to login on some server you can use simple setup:在 PHP 中,如果您想在某些服务器上登录,您可以使用简单的设置:

curl_setopt($cURL, CURLOPT_USERPWD, "USERNAME:PASSWORD");

Here is one my example how I use that:这是我如何使用它的一个例子:

$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, "imaps://server.com");
curl_setopt($cURL, CURLOPT_POST, 1);
curl_setopt($cURL, CURLOPT_POSTFIELDS,
        "postvar1=value1&postvar2=value2&postvar3=value3");
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($cURL, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($cURL, CURLOPT_TIMEOUT, 2);
curl_setopt($cURL, CURLOPT_USERPWD, "USERNAME:PASSWORD");
curl_setopt($cURL, CURLOPT_HTTPHEADER, array("auth=PLAIN"));
$output=curl_exec($cURL);
curl_close($cURL);

CURLOPT_USERPWD allow you to login on your server or application if you setup like that. CURLOPT_USERPWD 允许您在您的服务器或应用程序上登录,如果您这样设置。

If you need proxy, there is another way:如果您需要代理,还有另一种方法:

curl_setopt($cURL, CURLOPT_PROXYUSERPWD, "USERNAME:PASSWORD");

But you also need additional options for that:但是您还需要其他选项:

curl_setopt($cURL, CURLOPT_PROXY, '127.0.0.1'); // IP
curl_setopt($cURL, CURLOPT_PROXYPORT, '23'); // PORT
curl_setopt($cURL, CURLOPT_PROXYUSERPWD, "USERNAME:PASSWORD"); // Login

I hope this can help.我希望这会有所帮助。

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

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