PHP在表单提交后重定向到新页面 [英] PHP Redirect to new page after form submission

查看:304
本文介绍了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');
        }
}   
?>

这篇关于PHP在表单提交后重定向到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆