From eb744c5ef76485f6451fe6f0524af333b571b0c0 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 31 Aug 2006 07:45:58 +0000 Subject: [PATCH] redirect() now always respects delay 0 if specified + some minor changes --- lib/weblib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 921bb00bd9..d48ea68c38 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -4565,18 +4565,17 @@ function notice_yesno ($message, $linkyes, $linkno) { * the correct input) and then encode for where it's needed * echo ""; */ -function redirect($url, $message='', $delay='0') { +function redirect($url, $message='', $delay=-1) { global $CFG; - //$url = clean_text($url); if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { $url = sid_process_url($url); } $message = clean_text($message); - $url = html_entity_decode($url); // for php < 4.3.0 this is defined in moodlelib.php + $url = html_entity_decode($url); $url = str_replace(array("\n", "\r"), '', $url); // some more cleaning $encodedurl = htmlentities($url); $tmpstr = clean_text(''); //clean encoded URL @@ -4586,6 +4585,7 @@ function redirect($url, $message='', $delay='0') { /// when no message and header printed yet, try to redirect if (empty($message) and !defined('HEADER_PRINTED')) { + $delay = 0; //try header redirection first @header('HTTP/1.x 303 See Other'); //302 might not work for POST requests, 303 is ignored by obsolete clients @header('Location: '.$url); @@ -4595,8 +4595,8 @@ function redirect($url, $message='', $delay='0') { die; } - if (empty($delay)) { - $delay = 3; // if there is something already printed or message to display wait min 3 seconds + if ($delay == -1) { + $delay = 3; // if no delay specified wait 3 seconds } if (! defined('HEADER_PRINTED')) { print_header('', '', '', '', ''); @@ -4605,7 +4605,7 @@ function redirect($url, $message='', $delay='0') { echo '

'. $message .'

'; echo '

( '. get_string('continue') .' )

'; echo ''; - +// it might be better not to set timeout the same for both types of redirect, so that we can be sure which one wins ?>