是否可以通过使用 PHP 将用户重定向到不同的页面?
假设用户访问www.example.com/page.php并且我想将它们重定向到www.example.com/index.php ,如何在不使用元刷新的情况下这样做?可能吗?
www.example.com/page.php
www.example.com/index.php
这甚至可以保护我的页面免受未经授权的用户
function Redirect($url, $permanent = false) { if (headers_sent() === false) { header('Location: ' . $url, true, ($permanent === true) ? 301 : 302); } exit(); } Redirect('http://www.google.com/', false);
别忘了 die() / exit()!