【发布时间】:2018-03-05 17:23:49
【问题描述】:
我曾尝试在 PHP 中使用 cURL 登录到站点 https://play.binweevils.com,但我没有这样做。这是登录页面的 HTML FORM 代码:
<!--Login Form -->
<form id="login-play-form" action="https://www.binweevils.com/login" method="POST">
<input type="hidden" name="redirect_url" value="https://play.binweevils.com/game.php">
<input class="name login-payment-input" type="text" name="userID" id="userID" value="" required>
<input class="password login-payment-input" type="password" name="password" id="password" required>
<a class="remember-me" onclick="toggleTick(); return false;">
<label for="rememberMe">
<input type="checkbox" name="rememberMe" id="rememberMe" checked="checked">
<input type="hidden" name="form_token" id="form_token" value="aea58a7b633f2d75c0a6235a5ce65797" />
下面是我尝试的 PHP:
function login(){
$ch = curl_init("https://www.binweevils.com/login");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'userID=mo_salah&password=test&rememberMe=on&form_token=0c2fde897a3c212f5b7b759b45e023b2');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36 OPR/47.0.2631.55');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
}
由于某种原因,这不起作用。如果有人可以帮助进行任何修改,我将不胜感激。这是发布到 URL 的数据: Data being parsed to URL(请注意表单令牌不一样,每次都不同)
编辑:登录功能起作用
但是,当尝试通过 CURL 访问游戏中的 API 时,会发生错误。
function changeDef(login) {
$curl = curl_init("http://lb.binweevils.com/weevil/change-definition?rndVar=");
curl_setopt($curl, CURLOPT_POST, true);
define('USER_AGENT', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36');
curl_setopt($curl, CURLOPT_USERAGENT, USER_AGENT);
$timer = 201186;
$idx = 223743722;
$weevilDef = 422430521103011300;
$hash = "51f4aaecdd00ca5aa00cc7a48e2917d3";
curl_setopt($curl, CURLOPT_POSTFIELDS, "hash=".$hash."&weevilDef=".$weevilDef."&st=".$timer."&idx=".$idx);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
$responsedef = trim(curl_exec($curl));
curl_close($curl);
print $responsedef;
}
【问题讨论】:
-
每当您在没有足够信息的情况下进行故障排除时,与其随机尝试使其正常工作,不如尝试了解如何获取更多信息。在这种情况下,在
curl_exec($ch);之后执行以下操作:echo 'Curl error: ' . curl_error($ch); -
干杯,它说没有错误。
-
那么,如果没有错误但它“不起作用”,你能更具体一点吗?预期的结果是什么,你得到了什么结果?我们需要更多信息才能提供帮助。
-
请参阅编辑@BareNakedCoder
标签: php curl cookies login manual