moodle php 页面重定向继续页面在重定向时出现

moodle php page redirect continue page comes while redirecting

我有一个 moodle 页面,我正尝试使用重定向从该页面重定向到另一个页面,如下所示:

redirect("page2.php?cId=".$cid);

我被重定向到另一个页面,但在重定向时我正在查看如下内容:

看起来好乱。我想避免这种情况。

当前页面有 moodle 页眉和页脚,page2.php 没有 moodle 页眉和页脚

我怎样才能避免这个继续页面?

确保 Debugging 已启用(设置为 'Developer' 并显示)。

您可能会在此处看到一条警告消息,这可能解释了为什么重定向无法立即生效。

最有可能的解释是调用redirect之前已经输出了一些东西。在到达重定向之前查看您的代码以查找任何 'echo' 或 'print' 调用。

如果找不到任何 'echo' 或 'print' 调用,请确保在任何开头的“<?php”标记之前没有空格(或任何其他字符)你的文件,在你的文件末尾没有关闭'?>'标签(关闭PHP标签后很容易添加不需要的空格)并且没有不需要的内联HTML 节。

在您的代码中尝试以下操作:

redirect("page2.php?cId=".$cid, 'Loading', 1); 

这将显示 "Loading" 消息并延迟 1 秒。

您需要修改 moodle/lib 中的 outputrenderers.php 文件。 查找 redirect_message public 函数,您会看到一行内容类似于:

$output .= '<div class="continuebutton">(<a href="'. $encodedurl .'">'. get_string('continue') .'</a>)</div>'; 

使用 get_string 从 lang/en/moodle.php i18n 文件中选择另一个字符串,或者将其全部删除。例如,如果您想硬编码一条信息更丰富的消息:

$output .= '<div class="continuebutton">(<a href="'. $encodedurl .'">Please click here if you are not automatically redirected within '.$delay.' seconds</a>)</div>';