PHP在表单提交后重定向到新页面

问题描述:

我有一个表单,在表单提交后将用户重定向到page1.php。我想做的是在表单提交后将用户重定向到page2.php,但我需要确保POST请求已发送。示例:

I have a form, which redirects the user to "page1.php" after the form is submitted. What I want to do is to redirect the user to "page2.php" after the form is submitted, but I need to make sure that the POST request was sent. Example:

<form action="page1.php" method="POST">
<input type="text" name="username" />
<input type="text" name="age" />
<input type="submit" value="" />
</form>

当用户单击提交时,会将他重定向到page1.php。我想将他重定向到page2.php,但我需要确保数据发送到服务器。我不能使用AJAX。有没有办法用cURL或类似的东西?任何例子?

When the user clicks on Submit, it redirects him to page1.php. I want to redirect him to page2.php, but I need to make sure that the data is sent to the server. I can't use AJAX. Is there any way to do it with cURL or something like that? Any examples?

谢谢!


在page1.php

I guess this works !! In page1.php

<?php
//do establish session
//and check for the input fields obtained via $_POST
if(isset($_POST['name_of_your_field']) && !empty($_POST['name_of_your_field'])){
    if(!mail($to,$subject,$message)){
        header('location:form.php?msg=error');  
    }else{
        header('location:page2.php?msg=succes');
        }
}   
?>