2011-04-23 32 views
1

我正在製作一個PHP付款腳本,需要將交易結果POST到另一個服務器,然後重定向到另一個頁面。PHP腳本POST信息並重定向到另一頁

基本上,腳本具有事務值SUCCES,需要POSTED到www.domain.com/transaction.php,然後重定向到「confirmation.php」。

有人能告訴我我該怎麼做?

編輯:

這就是我一直在尋找:

<?php 
$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST); 
$r->setOptions(array('cookies' => array('lang' => 'de'))); 
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t')); 
$r->addPostFile('image', 'profile.jpg', 'image/jpeg'); 
try { 
    echo $r->send()->getBody(); 
} catch (HttpException $ex) { 
    echo $ex; 
} 
?> 

回答

4

可以使用對重定向頁面在PHP下面的代碼:

header('Location:confirmation.php'); 

,或者你可以用下面的代碼試試:

$postdata = http_build_query(
    array(
     'var1' => 'here your data', 
     'var2' => 'here your data' 
    ) 
); 

$opts = array('http' => 
    array(
     'method' => 'POST', 
     'header' => 'Content-type: application/x-www-form-urlencoded', 
     'content' => $postdata 
    ) 
); 

$context = stream_context_create($opts); 

$result = file_get_contents('http://www.domain.com/transaction.php', false, $context); 

使用該代碼,您可以使用php發佈您的數據。

+1

謝謝。這是我正在尋找的解決方案... – Andrei 2011-04-23 11:48:15

0

您需要在您的表單的action屬性後的網址。這裏有一個片段:

<form name="form" id="form" method="post" action="http://www.domain.com/transaction.php">..</form>

在你transaction.php文件,做任何你想要與所提交的數據做了,重定向,您可以使用header功能,像這樣:<?php header("Location: confirmation.php");

+0

我需要php代碼將信息自動發佈到另一個php頁面。我知道如何使用表格... – Andrei 2011-04-23 11:27:44