在表单提交或页面重定向被触发后,通常会将用户重定向到不同的页面或相同的页面,但格式不同。通常,您会通过编码来完成:
header('Location: destination.php'); exit();
这是一种完全可以接受的页面编码方式,但我更喜欢改用重定向功能。为什么?它更具可读性,老实说,我厌倦了编写 header('Location: ...');
代码。
function redirect($url, $permanent = false) { if($permanent) { header('HTTP/1.1 301 Moved Permanently'); } header('Location: '.$url); exit(); }
此功能非常易于使用,并节省了大量代码。