dq_1984 2015-01-11 16:49
浏览 43
已采纳

curl post参数php表单(客户端)

I am trying to retrieve different strings which are stored in php files, such as http://www.site_address.com/file.php. I have tried many curl commands, such as

curl -d "user=__&password=____" http://www.site_address.com/file.php

but all it doesn't really seem to work: it just returns a form action. This is how a file.php looks like:

<?php
$message="string";
if(isset($_POST['login']))
{
        if ($_POST['username'] != '' && $_POST['password'] !='') {
                if ($_POST['username'] == 'user' && $_POST['password'] == 'pass') {
                        echo $message;
                        exit();
                }
                else {
                        $error = 'failed!';
                }
        }
        else {
                $error = 'Error!';
        }
}

if (isset($error))
{
        echo $error;
}

?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        Username: <input type="text" id="username" name="username" size="32" value="" /><br />
        Password: <input type="password" id="password" name="password" size="32" value="" /><br />
        <input type="submit" name="login" value="Login" />
</form>

I have to add that I have no knowledge regarding PHP. In this case, I am simply the client. Do I have to use other flags for the curl command in order to get that string from "$message"?

  • 写回答

1条回答 默认 最新

  • doucan8276 2015-01-11 17:09
    关注

    The first thing you ought to add is the POST method to the curl command:

    curl -X POST
    

    And your form logic in that very PHP script depends on three present input variables. Namely username, password and login.

    curl -X POST -d "login=1&username=__&password=____" http://example.org/file.php
    

    The isset($_POST["login"]) check won't pass without the submit button name, and you wrote name instead of username.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮