PHP 实现页面跳转的 5 种方法
PHP 实现页面跳转的 5 种方法
本文将介绍 5 种常用的 PHP 页面跳转方法,并提供代码示例和注意事项。
1. 通过 header 函数跳转
header('Location: http://example.com');
2. 通过 HTML 的 meta 标签跳转
echo '<meta http-equiv='refresh' content='0;url=http://example.com'>';
3. 通过 JavaScript 跳转
echo '<script>window.location.href = 'http://example.com';</script>';
4. 通过 标签跳转
echo '<a href='http://example.com'>跳转到example.com</a>';
5. 使用 PHP 的 Location 函数
echo '<script>location.href='http://example.com'</script>';
**注意:**使用 header 函数进行跳转时,应该确保在调用 header 函数之前没有输出任何数据,否则会导致无法成功跳转。
原文地址: https://www.cveoy.top/t/topic/l4OG 著作权归作者所有。请勿转载和采集!