我想将某人重定向到index.php,我该怎么做?但不是“元”方法,因为它需要在标题中,我不能在那里。
答案 0 :(得分:2)
window.location.href = 'http://your-new-url.com';
或
window.location.pathname = 'index.php';
如果您需要使用相对路径名。
答案 1 :(得分:1)
不要使用JavaScript。如果用户禁用了JavaScript(或者很可能是在不支持JavaScript的情况下浏览浏览器),则重定向将无效。
从PHP代码中,您可以发送HTTP标头,将用户定向到您选择的页面。使用header()
功能执行此操作。
header('Location: index.php');
exit; // Important, stops execution of PHP page
如果PHP因为数据已经发送到浏览器而抱怨它无法发送标头,只需转到脚本的顶部并使用ob_start()
启用输出缓冲:
ob_start();
启用输出缓冲后,您可以在代码中的任何位置发送标头,因为数据仅在脚本结束时发送。
答案 2 :(得分:0)
<script type="text/javascript">
window.location.href = "http://www.yoursite.com/index.php"
</script>
答案 3 :(得分:0)