gpt4 book ai didi

PHP header 刷新警告

转载 作者:行者123 更新时间:2023-12-04 22:25:54 25 4
gpt4 key购买 nike

我有这个代码:

<?php
session_start();
echo "".$_SESSION['eventnum']."";
$urlRefresh = "testremot.php";
header("Refresh: 5; URL=\"" . $urlRefresh . "\"");
?>

但是 header 不起作用,并且当我尝试运行此代码时出现此警告:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\remot\testremot.php:3) in C:\xampp\htdocs\remot\testremot.php on line 5**

你能帮我吗?

最佳答案

好的,让我们看看第 3 行中有什么内容:

echo "".$_SESSION['eventnum']."";

显然,您正在此行中生成输出 (echo),并且此行出现在您调用 header 之前。
将其移至 header 下方:

session_start();
$urlRefresh = "testremot.php";
header("Refresh: 5; URL=\"" . $urlRefresh . "\"");
echo "".$_SESSION['eventnum']."";

但请注意(来自 Wikipedia ):

The W3C's Web Content Accessibility Guidelines (7.4) discourage the creation of auto-refreshing pages, since most web browsers do not allow the user to disable or control the refresh rate.

关于PHP header 刷新警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2919851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com