I need to save the data from the form, and then send the user to pay to the bank, do this:

$url="http://site.com"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded; Content-Length:".strlen($postData).";")); curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch, CURLOPT_COOKIEFILE, ''); $html=curl_exec($ch); if (FALSE === $html) throw new Exception(curl_error($ch), curl_errno($ch)); $redirectURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); curl_close($ch); 

I think so (because I didn’t have a special deal with cURL before) to redirect to the landing page, but instead just the content of the page is returned. There are no safe_mode and open_basedir settings on the server. What am I doing wrong?

  • one
    Curl runs on the server side. As far as I understand, you need to redirect to the client’s bank (i.e. browser). To do this, send the browser a header: header ("Location: YOUR_URL"); - Anton Zikov
  • I can not, because I need to send more data through POST. Instead of cURL, it was decided to generate the form and submit it via JavaScript. - DaemonHK
  • If you need to drag a post to the payment page, why not just send $ _post there? - Kirill Korushkin

2 answers 2

As said in the comments you need to send the user through the header

 header("Location: http://www.host.ru"); exit(); 

I pay attention that before the header there should be no conclusions on the screen otherwise there will be errors

    Very similar task was engaged recently. Also tried through curl - the data is sent to the bank, but the browser does not go. Over time, I realized a rather simple thing - curl is executed on the server and cannot control the browser.

    The solution is this. I receive data from the user in my form (on the client site shop on WooCommerce). I process this data in my payment gateway plugin (including the digital signature generated in my code). I send a get request (just a redirect) to a page on my site with parameters for a bank. The browser goes to this address. I accept the request on my website, on the fly in php I generate a form with the data for the bank, along with a script that "clicks" in it to submit . The browser goes to the payment page in the bank via POST .

    The function to form the form and submit it is below.

     function check_for_sdm() { if( isset($_GET['sdm_gateway']) ) { $action = $_GET['sdm_gateway']; if ($action == 'post') { if (isset($_GET['sdm_mode'])) $sdm_mode = $_GET['sdm_mode']; else $sdm_mode = ''; if ($sdm_mode == 'test') $gateway_link = 'https://3dst.sdm.ru/cgi-bin/cgi_link'; else $gateway_link = 'https://3ds.sdm.ru/cgi-bin/cgi_link'; ?> <form id="sdm_form" action="<?php echo $gateway_link; ?>" method="post"> <?php foreach ($_GET as $a => $b) { if (($a !== 'sdm_gateway') && ($a !== 'sdm_mode')) { $input = '<input type="hidden" name="'.htmlentities($a).'" value="'.htmlentities($b).'">'; echo $input; } } ?> </form> <script type="text/javascript"> document.getElementById('sdm_form').submit(); </script> <?php die(); } } }