php中页面重定向的语法,PHP页面重定向

参见英文答案 > How do I make a redirect in PHP?                                    31个

PHP可以在执行函数后进行重定向调用吗?我正在创建一个函数,我希望它能够重定向到位于同一根文件夹中的文件.可以吗?

if {

//i am using echo here

}

else if ($_SESSION['qnum'] > 10) {

session_destroy();

echo "Some error occured.";

//redirect to user.php

}

解决方法:

是的,您将使用header功能.

/* Redirect browser */

header("Location: http://www.yourwebsite.com/user.php");

exit();

在它之后调用exit()是一个好习惯,这样它下面的代码就不会被执行.

另外,从文档:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

这意味着你不应该在header()函数之前回显任何东西,因为这样做很可能会抛出错误.此外,您还需要验证此代码是否在任何其他输出之前运行.

标签:php,redirect,header

来源: https://codeday.me/bug/20190915/1805960.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值