在 PHP 中实现页面跳转有多种方法,以下是其中一种常用的方法:
<?php
// 跳转到指定的 URL
header("Location: http://example.com/page2.php");
exit; // 确保在跳转后停止执行当前页面的代码
?>
<?php
// 输出 JavaScript 代码实现跳转
echo '<script>window.location.href = "http://example.com/page2.php";</script>';
exit; // 确保在跳转后停止执行当前页面的代码
?>
<?php
// 输出 HTML 代码实现跳转
echo '<meta http-equiv="refresh" content="0;URL=\'http://example.com/page2.php\'" />';
exit; // 确保在跳转后停止执行当前页面的代码
?>
这些方法可以根据需要在 PHP 页面中的适当位置使用,以实现页面跳转功能。请注意,在执行页面跳转之前,确保没有输出任何 HTML 或文本内容,否则会导致跳转失败。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站