Posting a textarea form with cURL

2019-07-26 07:30发布

How would I go about posting a textarea form?

<form method="post" action="/user/test/shoutbox/add" id="shoutPost" class="clearit">
<input name="formtoken" type="hidden" value="852f8fde54190fa5f9aa47172d492f829c1b"/>
<input type="hidden" name="backto" value="/user/test/shoutbox" />
<textarea id="shoutmsg" name="message"></textarea>
<input type="submit" name="submit" class="confirmButton" value="Post" id="sbPost"  />

This should work right?

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
$postfields .= "&message=".$msg;
$postfields .= "&submit=sbPost";
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);

but it's not posting for some reason...

3条回答
爷的心禁止访问
2楼-- · 2019-07-26 08:07

Where is $msg coming from? your text area has name="message", try changing $msg to $_POST['message']

查看更多
Summer. ? 凉城
3楼-- · 2019-07-26 08:18
    curl_setopt($ch, CURLOPT_REFERER,"URLHERE");
    curl_setopt($ch, CURLOPT_URL,"URLHERE");
    curl_setopt($ch, CURLOPT_POST, 0);
    $page = curl_exec($ch);

    $formtoken = explode('name="formtoken" type="hidden" value="',$page);
    $formtoken = explode('"/> ',$formtoken[1]);
    $formtoken = $formtoken[0];

    $backto = explode('type="hidden" name="backto" value="',$page);
    $backto = explode('" />',$backto[1]);
    $backto = $backto[0];

    curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-$randnum");
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_URL,"URLHERE");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_POST, 1);
    $postfields = "formtoken=".$formtoken;
    $postfields .= "&backto=".$backto;
    $postfields .= "&message=".$msg;
    $postfields .= "&submit=Post";
    curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
    $page = curl_exec($ch);
查看更多
倾城 Initia
4楼-- · 2019-07-26 08:24

Forgot the curl_exec?

curl_exec($ch);
查看更多
登录 后发表回答