A
A
Alexander2021-07-30 21:47:51
PHP
Alexander, 2021-07-30 21:47:51

How to handle redirect when submitting form data via cURL?

Greetings colleagues!

I have an auto submit form:

echo '<html><body>';
    echo '<center><form name="form" method="POST" action="https://paysite.ru/quickpay/confirm.xml">'
    . '<input type="hidden" name="receiver" value="123123123">'
    . '<input type="hidden" name="formcomment" value="Донат проекта">'
    . '<input type="hidden" name="short-dest" value="Донат проекта">'
    . '<input type="hidden" name="label" value="' . $ID . '">' //ID для обработки уведомления об оплате
    . '<input type="hidden" name="quickpay-form" value="donate">'
    . '<input type="hidden" name="targets" value="Добровольный взнос для поддержки проекта">'
    . '<input type="hidden" name="sum" value="1" data-type="number">'
    . '<input type="hidden" name="comment" value="Хотелось бы получить демонстрационный доступ.">'
    . '<input type="hidden" name="need-fio" value="false">'
    . '<input type="hidden" name="need-email" value="false">'
    . '<input type="hidden" name="need-phone" value="false">'
    . '<input type="hidden" name="need-address" value="false">'
    . '<div id="parent">'
    . '<input type="image" name="paymentType" value="AC" src="/donate.png" width="500" alt="Нажми для оплаты">'
    . '</div><br>'
    . '</form></center>';
    echo "<script>document.getElementsByTagName('form')[0].submit();</script>"; //Отправляем форму в автомате
    echo '</body></html>';


Decided to redo it with cURL without these stub pages:
$target_url = "https://paysite.ru/quickpay/confirm.xml";
$postfields = [
    receiver => '123123123',
    formcomment => 'Донат проекта',
    short-dest => 'Донат проекта',
    label => 'AKDHFAKJH3KHJ', //Для примера
    quickpay-form => 'donate',
    targets => 'Добровольный взнос для поддержки проекта',
    sum => 1,
    comment => 'Хотелось бы получить демонстрационный доступ',
    need-fio => 'false',
    need-email => 'false',
    need-phone => 'false',
    need-address => 'false',
    paymentType => 'AC'
];

$curl = send_cURL($target_url, $postfields); 

function send_cURL($url, $postfields = FALSE) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    if ($postfields) {
        curl_setopt($curl, CURLOPT_POST, TRUE);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
    }
    $result = curl_exec($curl);
    curl_close($curl);
    $result = json_decode($result, TRUE);
    return $result;
}


The page https://paysite.ru/quickpay/confirm.xml after loading redirects to https://paysite.ru/transfer/quickpay?requestId=343... ...

How can I process this when called via cURL?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Yakovlev, 2021-07-31
@sergeyakovlev

https://www.php.net/manual/ru/function.curl-setopt.php
Parameter CURLOPT_FOLLOWLOCATION

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question