2014-02-17 77 views
2

如果我使用帖子將表單提交到php頁面,我可以在通過使用header('location: ...php')重定向到達的頁面上使用這些帖子值嗎?

例子:是否通過php頭重定向發佈數據持久性?

<form action="welcome.php" method="post"> 
    Name: <input type="text" name="name"><br> 
    E-mail: <input type="text" name="email"><br> 
    <input type="submit"> 
</form> 

上的welcome.php,如果我做header("Location: welcomBack.php")我還可以訪問$_POST['Name']$_POST['E-mail'] ...(從welcomeBack.php)?

+1

不可以。 – mario

回答

0

,你不能。重定向到另一個頁面將意味着在另一個頁面中,並且沒有$_POST值,也不會$_POST數組可用。另一方面,您仍然可以傳遞值鏈接本身並在其他頁面中可用。例如

header('location: other.php?data=one'); 

因此,在其他頁面,您可以使用

echo $_GET['data']; 
//print one 

至於阿里納斯,我會加你可以重定向到一個表單操作的另一頁,然後有在其他網頁中所有可用值$_POST array

+0

我怎麼會用你表達的方式重定向到另一個表單動作的頁面? –

+0

請檢查這裏的文檔http://www.w3schools.com/TAGS/att_form_action.asp只要將你的動作從'action =「welcome.php」'改爲'action =「welcomeBack.php」' – Fabio