在PHP中,可以使用header()
函数来实现页面跳转。
以下是使用header()
函数跳转页面的示例代码:
<?php// 跳转到指定URLheader("Location: http://www.example.com");// 延迟跳转到指定URL,延迟时间为2秒header("Refresh: 2; url=http://www.example.com");// 跳转到相对路径的页面header("Location: relative/path/to/page.php");?>
需要注意的是,header()
函数必须在任何实际的输出之前调用,包括空格和换行符。另外,如果要使用header()
函数跳转页面,需要确保在调用该函数之前没有输出任何内容到浏览器。