重定向和盲重定向_PHP重定向功能

重定向和盲重定向

After form submission or a page redirect is triggered, it's commonplace to redirect the user to a different page or to the same page, formatted in a different way. Usually, you'd complete this by coding:

触发表单提交或页面重定向后,通常将用户重定向到其他页面或同一页面,并以不同的方式进行格式化。 通常,您可以通过编码来完成此操作:

header('Location:  destination.php');
exit();

This is a completely acceptable way to code your pages, but I prefer to use a redirect function instead. Why? It's much more readable, and quite honestly, I'm tired of writing the header('Location: ...'); code.

这是一种完全可以接受的页面编码方法,但是我更喜欢使用重定向功能。 为什么? 它更具可读性,说实话,我已经厌倦了编写header('Location: ...'); 码。

function redirect($url, $permanent = false) {
	if($permanent) {
		header('HTTP/1.1 301 Moved Permanently');
	}
	header('Location: '.$url);
	exit();
}

This function is incredibly easy to use and saves a lot of code.

此功能非常易于使用,并节省了大量代码。

翻译自: https://davidwalsh.name/php-redirect-function

重定向和盲重定向

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值