1

我正在开发一个项目,我有一个计费服务器(服务器 1)和一个控制面板服务器(服务器 2 / Virtualmin),其中计费系统必须在服务器 2 上执行一个接受变量的脚本,但服务器 2 上的文件需要验证。

我能够在不同的服务器上使用 shell 命令来实现我想要的,如下所示:

wget --http-user=root --http-passwd=pass --no-check-certificate https://example.com:10000/virtual-server/remote.cgi?program=create-domain&domain=example.net&pass=123&default-features

这样做的问题是计费服务器只能执行特定的 PHP 文件,并且服务器没有安装 wget,所以我不能用 shell_exec 来做。

我尝试使用 PHP cURL,但是我真的不知道如何使用它,并且它不起作用。这是我尝试过的:

$serverip = "example.com:10000";
$domain = "example.net";
$password = "123";

$ch = curl_init("https://$serverip/virtual-server/remote.cgi?program=create-domain&domain=$domain&pass=$password&default-features");

$userpwd = 'root:pass';

curl_setopt($ch, CURLOPT_USERPWD, $userpwd);

curl_exec($ch);
curl_close($ch);

如果您需要更多详细信息,请告诉我,我很乐意提供更多信息。在此先感谢,我知道这看起来很奇怪。

编辑一个 这是我尝试过的新代码,但仍然无法正常工作。

<html>
<h1>Provision Test</h1><hr />

<?php

$domain = "example.net";
$password = "123";
$serverip = "example.com:10000";

$ch = curl_init();

$userpwd = 'root:pass';

curl_setopt($ch, CURLOPT_URL, "http://{$serverip}/virtual-server/remote.cgi?program=create-domain&domain={$domain}&pass={$password}&default-features");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);

curl_exec($ch);
curl_close($ch);

?>

</html>

编辑二 似乎可以很好地执行上述代码(编辑 1),但只能通过 CLI 执行,并且当通过 Web 界面尝试时,没有任何反应,脚本会在遇到 curl_init(); 时停止。任何想法将不胜感激。

4

0 回答 0