0

$_POSTの送信に関する問題を解決する方法がわかりません。example.comのフォームに記入したい

//at example.com
<form action="foo.php" method="post" >
<input name="bar1" type="text" />
<input name="bar2" type="text" />
<input name="bar3" type="text" />
<input value="Send" type="submit" />
</form>

そしてそれはfoo.phpに行きます:

<?php //foo.php
echo 'added: <p>'.$_POST['bar1'].'<br />'.$_POST['bar2'].'<br />'.$_POST['bar3']; 
?>

同時に送信します

$_POST['bar1'], $_POST['bar2'], $_POST['bar3']

exampledomain.com/foobar.phpに移動すると、ファイルに保存できます。これは問題ではありません。

両方のphpスクリプトに一度に情報を送信する方法がわかりません。1つは外部スクリプトです。どういうわけかfoo.php内に送信する必要があると思います

ある種の解決策があります-foo.php内のexampledomain.com/foobar.phpにリダイレクトしますが、私の場合は受け入れられません-ユーザーにexample.comを終了させずにやりたいです

事前に感謝し、あなたが私の問題を理解できることを願っています-コメントをするだけではない場合

編集:ピートハーバートペニートの答えに基づいて:

 <?php //inside foo.php
 $url = 'http://exampledomain.com/foobar.php';
 $fields_string='';
 foreach($_POST as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
 rtrim($fields_string,'&');

 //open connection
 $ch = curl_init();

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

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

 //close connection
 curl_close($ch);

  ?>
4

3 に答える 3

2

CURLを使用してPOSTリクエストを作成します。

<?php
 // these variables would need to be changed to be your variables 
 // alternatively you could send the entire post constructed using a foreach
 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.site.com/cgi-bin/waiting.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);
?>

リンクから:

http://www.askapache.com/php/sending-post-form-data-php-curl.html

于 2012-05-31T16:54:19.583 に答える
1

あなたのfoo.php

<?php
include 'http://exampledomain.com/foobar.php';

注:allow_url_fopenファイルで有効にする必要がありphp.iniます。

于 2012-05-31T16:51:44.280 に答える
0

JavaScriptajaxを使用してPOSTの1つを実行する必要があります。

次に、通常のようにブラウザをリダイレクトする実際の投稿。

http://www.w3schools.com/jquery/ajax_post.asp

$(selector).post(url,data,success(response,status,xhr),dataType)
于 2012-05-31T16:57:06.463 に答える