我正在寻找如何通过 PHP 与我们的计费软件 (WHMCS) 建立会话,以便我可以调用仅对登录管理员可用的 URL。我不相信我可以将登录数据和参数都传递给 URL,所以我相信必须首先进行会话,然后调用 URL。
系统中的实际 php 已编码,但从查看源代码来看,它看起来如下...
<form action="dologin.php" method="post" name="frmlogin" id="frmlogin">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="30%" align="right" valign="middle"><strong>Username</strong></td>
<td align="left" valign="middle"><input type="text" name="username" size="30" class="login_inputs" /></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle"><strong>Password</strong></td>
<td align="left" valign="middle"><input type="password" name="password" size="30" class="login_inputs" /></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle"><input type="checkbox" name="rememberme" id="rememberme" /></td>
<td align="left" valign="middle"><label for="rememberme" style="cursor:hand">Remember me until I logout.</label></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle"> </td>
<td align="left" valign="middle"><table width="100%" cellpadding="0" cellspacing="0"><tr><td><input type="submit" value="Login" class="button" /></td><td align="right">Language: <select name="language" class="login_inputs"><option value="">Default</option><option value="czech">Czech</option><option value="english">English</option><option value="french">French</option><option value="portugues">Portugues</option></select></td></tr></table></td>
</tr>
</table>
</form>
我是否应该能够像下面这样进行 CURL 调用,然后调用 URL?
$url = "https://clients.website.com/admincp/dologin.php";
$username = "admin";
$password = "239asd90";
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($ch);
if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
curl_close($ch);