Diese kleine Funktion garantiert, dass Besucher zu einer URL weitergeleitet werden. Zuerst versucht die Funktion, den Benutzer mit der header() Funktion weiterzuleiten, geht das nicht, wird Javascript und META-Refresh versucht. Wenn auch das nicht geht, wird ein Link angezeigt.
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 "<a href="$url">$url</a>
";
print 'If you are not, please click on the link above.
';
print '';
print '';
// Stop the script here (optional)
if ($exit) exit;
}
Quelle: jonasjohn.de[/php]