温馨提示×

php如何使用header()跳转页面

PHP
小云
114
2023-08-24 14:58:42
栏目: 编程语言

在PHP中,可以使用header()函数来实现页面跳转。

以下是使用header()函数跳转页面的示例代码:

<?php
// 跳转到指定URL
header("Location: http://www.example.com");
// 延迟跳转到指定URL,延迟时间为2秒
header("Refresh: 2; url=http://www.example.com");
// 跳转到相对路径的页面
header("Location: relative/path/to/page.php");
?>

需要注意的是,header()函数必须在任何实际的输出之前调用,包括空格和换行符。另外,如果要使用header()函数跳转页面,需要确保在调用该函数之前没有输出任何内容到浏览器。

0