douquanjie9326 2010-12-19 06:54
浏览 73
已采纳

如何从php脚本发送重定向页面传递变量作为post变量

you can find a similar question here PHP Post Request inside a POST Request but this is not working in my context.

I have a form (reservation form for a tour website) and when the form is submitted, the values are processed in a script like validation and calculation of values and sending email.

after processing the variables, i want to send it to a page for payment and this page will post payment details to paypal.

My question is after the reservation form is submitted, after processing values retrieved from reservation from, how can i redirect the page in such a way that the variables will be passed as post variables. (I am not looking from response from the other form, i want to redirect to the other form).

  • 写回答

3条回答 默认 最新

  • doujiao0110 2010-12-19 07:02
    关注

    To create a POST request, open a up a TCP connection to the host using fsockopen(), then use fwrite() on the handler returned from fsockopen() with the same values you used in the header functions in the OP. Alternatively, you can use cURL.

    <?php
     if(isset($_POST['Name']))     $Name   = $_POST['Name'];
     if(isset($_POST['Email']))   $Email   = $_POST['Email'];
     if(isset($_POST['Message']))   $Message= htmlentities($_POST['Message']);
    
     $Curl_Session = curl_init('http://www.yoururl.com/script.php');
     curl_setopt ($Curl_Session, CURLOPT_POST, 1);
     curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "Name=$Name&Email=$Email&Message=$Message");
     curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
     curl_exec ($Curl_Session);
     curl_close ($Curl_Session);
    ?>
    

    Where $Message would be your variables.

    EDIT: i answered this long ago maybe i did forget to reference from php.net but here is the link per comment http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html as Reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘