function safe_redirect($url, $exit=true) { // Only use the header redirection if headers are not already sent if (!headers_sent()){ header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $url); // Optional workaround for an IE bug (thanks Olav) header("Connection: close"); } // HTML/JS Fallback: // If the header redirection did not work, try to use various methods other methods print ''; print 'Redirecting you...'; print ''; print ''; print ''; // If the javascript and meta redirect did not work, // the user can still click this link print 'You should be redirected to this URL:
'; print "$url

"; print 'If you are not, please click on the link above.
'; print ''; print ''; // Stop the script here (optional) if ($exit) exit; } //该片段来自于http://yuncode.net