A function that redirects the user to the specified URL by sending the appropriate headers or by using JavaScript if the headers were already sent.
1. function RedirectToUrl($ToUrl)
2. {
3. // If an URL was passed
4. if(strlen($ToUrl) > 0)
5. {
6. // If headers were already sent, use JavaScript
7. if(headers_sent())
8. {
9. echo "<script type=\"text/javascript\">document.location.href=\"".$ToUrl."\";
</script>\n";
10. }
11. else // Sent redirect headers
12. {
13. header("Location: ".$ToUrl);
14. }
15. exit();
16. }
17. }