我想重定向用户从page1到page2与一些POST数据。page1和page2是在两个不同的域,我有控制这两个他们
第1页
<?php
$chars="stackoverflowrules"
?>
我想提交字符作为一个帖子数据和重定向到页面2。
然后第2页,我想使用POST数据,如
<?php
$token = $_POST['chars'];
echo $token;
?>
我使用了一个表单和JS
第1页
<?php
$chars="stackoverflowrules";
?>
<html>
<form name='redirect' action='page2.php' method='POST'>
<input type='hidden' name='chars' value='<?php echo $chars; ?>'>
<input type='submit' value='Proceed'>
</form>
<script type='text/javascript'>
document.redirect.submit();
</script>
</html>
第2页
<?php
$token = $_POST['chars'];
echo $token;
?>
- 在第1页,使用
curl
将数据发布到第2页。 - 将POST'ed数据存储在某个地方(数据库?)。
- 从第1页重定向到第2页
- 检索回数据。
您需要使用curl()
。
在page1.php上执行以下操作:
$data = $_POST;
// Create a curl handle to domain 2
$ch = curl_init('http://www.domain2.com/page2.php');
//configure a POST request with some options
curl_setopt($ch, CURLOPT_POST, true);
//put data to send
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//this option avoid retrieving HTTP response headers in answer
curl_setopt($ch, CURLOPT_HEADER, 0);
//we want to get result as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute request
$result = curl_exec($ch);
// now redirect to domain 2
header("Location: http://domain2.com/page2.php");
在第2页,您可以检索POST数据:
<?php
$token = $_POST['secure_token'];
echo $token;
?>