1

There is a contact form which current action is http://www.siteA.com/ContactInfo.php, it sends fields and values. In ContactInfo.php, i just catch the values and send and email to y@z.x

BUT, inside ContactInfo.php, I need to send the same data to another destination, in other domain http://www.SiteB.com/Reg.aspx

I have tryed out to create an http POST request to SiteB, but It doesn't work, even with another file in the same site.

I have not the code right now, but it's similar to this structure.

<? php
   //ContactInfo.php
   // CATCTH VALUES and SEND EMAIL

   // CREATE Http POST REquest to another www.siteB.com/Reg.aspx
?>

I have tryed out using... HttpRequest object, cURL, and the other one...i can't remember the name.

4

3 回答 3

2

您可以使用 cURL ( http://www.php.net/manual/en/curl.examples.php ) 尝试这样的事情。

$sub_req_url = "http://www.siteB.com/Reg.aspx";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);

羞涩

于 2010-02-20T08:01:42.363 回答
1

I'd encourage you to try the Snoopy Class. It's really rather simple:

<?php

  $vars = array("fname"=>"Jonathan","lname"=>"Sampson");
  $snoopy = new Snoopy();

  $snoopy->httpmethod = "POST";
  $snoopy->submit("http://www.siteB.com/Reg.aspx", $vars);

  # Use the following if you need to view the results
  # print $snoopy->results;

?>
于 2010-02-20T05:05:58.067 回答
0

如果没有看到您的代码,很难说出问题所在。

问题:

站点 B 是您也拥有的域,还是第三方?如果是第三方,他们可能正在运行机器人检查等,这会使您的 POST 失败。

你有没有做任何事情来确认数据实际上正在发送到域 B?

如果域 B 也在您的控制之下,我的猜测是它们在同一个 Web 服务器上运行 - 为什么不将逻辑写入域 A 页面,该页面执行任何需要完成的操作,而无需提交到域 B?

于 2010-02-20T08:07:03.990 回答