重定向和盲重定向
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.
此功能非常易于使用,并节省了大量代码。
翻译自:
重定向和盲重定向