Let's start with your post.
If you could use correct english with punctuation it would help others enourmously in understanding you.
If you separate your problems into well defined questions, one can answer them.
Currently it's in one heap...I'll try to pick it out though.
Error tracking: try to put down what's your goal, what have you attempted, and what has happened instead of what. Where do you suspect the problem is. How did you try to fix it. You'll find that in most cases this leads to a simple solution already, or you can find it in the annoted php manual in 2 minutes.
Redirecting: you already got a header location: output. You can use the file name only for redirecting locally, helps portability too. Eg: header("location:index.php");
The redirect works, unless you have other output before that, but in that case an error should be thrown. Try setting error reporting to 255 for development, it helps to avoid other sloppy coding.
"Php writing to top of file":
if you mean re-writing part of a HTML page, I recommend AJAX. (there's a pretty good simple tutorial right here on phpbuilder.)
With the cookie I don't know what you've attempted and how it wasn't working / what help you need.