dongyuan9149 2018-07-26 10:51
浏览 33

如何在php中使用curl发布表单并重定向到表单操作?

How do I post this form:

<form action ="http://google.com" id="checkpayment" style="display:none" method="post">
        <input value="crm_pg1" name="uid">
        <input value="98" name="passcode">
        <input value="10" name="payamnt">
        <input value="150001451" name="session">
        <input value="demo@gmail.com" name="emailid">
        <input value="9865321478" name="mobileno">
        <input value="normal" name="paytype">
        <input value="home" name="segment">
        <input value="FTTH" name="sub_segment">
        <input value="http://example.com" name="returnurl">
        <INPUT TYPE ="SUBMIT">
        </form>

and I am using this php code:

$curl_connection =
          curl_init('http://google.com');

        //set options
        curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($curl_connection, CURLOPT_USERAGENT,
          "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, false);
        curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

        //set data to be posted
        curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

        //perform our request
        $result = curl_exec($curl_connection);
        //show information regarding the request
         print_r(curl_getinfo($curl_connection));
        echo curl_errno($curl_connection) . '-' .
                        curl_error($curl_connection);

        //close the connection
        curl_close($curl_connection); 

I don't know if it's working or not, but how do I post a form and redirect to form action?

For example if I posted this form using curl from my site i.e; example.com and after successful submit its redirect to google.com.

  • 写回答

1条回答 默认 最新

  • dosi8657 2018-07-26 10:58
    关注

    First your action should be the php file you want to post the data from the form to. Second you can get the data from the form with $_POST in the .php file Third, after you make the call to api with curl you can redirect with header('Location: http://www.example.com/');

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了