PHP - 如何检索这些APIS的访问权限?

时间:2018-03-05 17:23:49

标签: php curl cookies login manual

我曾尝试在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;
}

错误如下:Error我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

因此,Web应用程序拒绝您的请求,因为“userIDX”的值不在其会话数据中。在不知道网络应用程序的代码的情况下,很难知道除了猜测之外的其他原因。你确实发送了idx=...所以我猜测它会获得“userIDX”的价值。

猜猜#1(手指交叉):[curl_setopt()1的PHP文档说有两种方法可以设置CURLOPT_POSTFIELDS:字符串或数组。然后它说“如果value是一个数组,Content-Type标题将被设置为multipart / form-data”。这意味着如果value是string,则不设置此标头。并且(在这里猜测)这可能是它没有得到idx的原因。所以,试试这个(交叉时):

curl_setopt($curl, CURLOPT_POSTFIELDS, [ 
    "hash" => $hash, 
    "weevilDef" => $weevilDef,
    "st" => $timer,
    "idx" => $idx
]);
相关问题