PHP 中的重定向 [英] Redirect in PHP
问题描述
我有一个典型的mail.php 脚本,它使用mail() 函数.在用户将信息输入到典型的 HTML 表单后,我让 mail() 函数将电子邮件发送到所需的电子邮件 [使用 mail($email_of_client) 等]
I have a typical mail.php script, which uses the mail() function. After the user inputs information into a typical HTML form, I have the mail() function send the email to the desired email [with mail($email_of_client) etc etc]
我的问题是:
在电子邮件发送后,我希望用户被重定向到一个ThankYou 页面(在 wordpress 下运行,因此它没有 .html 或 .php 扩展名)
After the email sends, I want the user to be redirected to a ThankYou page (run under wordpress, so it doesn't have .html or .php extensions)
我尝试了以下方法:
<meta http-equiv="refresh" content="0;URL=http://my-site-here.com/thankyou">
这可以完成工作,但会显示一毫秒的空白屏幕.我想知道是否可以在用户输入数据并点击发送后立即进行重定向.
This does the job, but shows a blank screen for a millisecond. I was wondering if it's possible to do a right away redirect after the user inputs the data and clicks on send.
非常感谢,
阿米特
推荐答案
不要使用元刷新,而是使用
Instead of using the meta refresh, use
header('Location: http://my-site-here.com/thankyou');
exit();
如果您不想执行该行之后的内容,请不要忘记 exit()
Do not forget about exit() if you don't want to execute what's after that line
如果您没有向浏览器发送任何内容,这将起作用.如果您必须向浏览器发送任何内容,解决方案是:
This works if you didn't sent anything to the browser. If you had to send anything to the browser the solution is:
ob_start();
echo "sending something to the browser";
header('Location: http://my-site-here.com/thankyou');
ob_end_clean();
exit();
这篇关于PHP 中的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!