If you echo any thing before calling the header it will fail.
I use a messy but useful function that can be called when needed.
Make a functions.php & add this:
function c4redirect($redirect)
{
echo "
<HEAD>
<SCRIPT LANGUAGE=\"JavaScript\">
<!-- Begin
redirectionTime = \"3000\";
redirectionURL = \"".$redirect."\";
function redirectionTimer() { self.setTimeout(\"self.location.href = redirectionURL;\",redirectionTime); }
// End -->
</script>
</head>
<body onLoad=\"redirectionTimer()\">
<META HTTP-EQUIV=Refresh CONTENT='4; URL=$redirect'>
";
}
You can add any as many functions to this page as you like over time.
To sue the function you must firstly call/load the functions page.
include("functions.php");
Then all you need to do every time you want to use the redirect is:
c4redirect("index.php")