PHP脚本POST信息并重定向到另一个页面

时间:2011-04-23 11:18:36

标签: php

我正在制作一个PHP支付脚本,需要将交易结果发布到另一台服务器,然后重定向到另一个页面。

基本上,脚本的事务值SUCCES需要发布到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;
}
?>

2 个答案:

答案 0 :(得分: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 :(得分:0)

您需要在表单的action属性中使用post URL。这是一个片段:

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

在您的transaction.php文件中,对提交的数据执行任何操作,对于重定向,您可以使用header函数,如下所示:<?php header("Location: confirmation.php");