我如何使用PHP发布外部表单? [英] how can I post an external form using PHP?

查看:123
本文介绍了我如何使用PHP发布外部表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

外部表单

<form action="MyForm.action" method="post">  

托管在不同的服务器上。

hosted on a different server.

我希望我的PHP脚本发布此表单并显示结果。

I want my PHP script to post this form and display the results

我该如何做?

How can I do this?

推荐答案

要从PHP脚本发布表单,您可以使用cURL。这是一个例子

To post a form from a PHP script you'd use cURL. Here is an example

<?php
  $url = 'http://domain.com/get-post.php';
  $fields = array(
    'lname'=>urlencode($last_name),
    'fname'=>urlencode($first_name),
  );

  //url-ify the data for the POST
  foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
  rtrim($fields_string,'&');

  // Initialize curl
  $ch = curl_init();

  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_POST,count($fields));
  curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

  //execute post
  $result = curl_exec($ch);

  // Results of post in $result
?>

这篇关于我如何使用PHP发布外部表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆