开发者

how to redirect to another page while sending post vars

开发者 https://www.devze.com 2023-01-02 05:03 出处:网络
What I want to do is when user goes to one page I redirect him to a开发者_开发知识库nother page while sending some post variables to this latter page. You can\'t redirect a user and simultaneously sen

What I want to do is when user goes to one page I redirect him to a开发者_开发知识库nother page while sending some post variables to this latter page.


You can't redirect a user and simultaneously send any POST data.


You can't do it with just PHP. It's possible with Javascript however:

<form id="f" method="post" action="http://example.com">
<input type="hidden" name="var1" value="value1" />
<input type="hidden" name="var2" value="value2" />
</form>
<script type="text/javascript">
window.onload = function () {
   document.getElementById('f').submit();
}
</script>

You might want to load the values and names with PHP.


While it is true you cannot send variables into the $_POST array while redirecting you can use sessions to store the data and then redirect.

so

session_start();

$_SESSION['post_array'] = $_POST;

header("Location: next_page.php");

Then on next_page.php

session_start();

$_SESSION['post_array'] contains all the post variables from the previous page

0

精彩评论

暂无评论...
验证码 换一张
取 消