you can use it anywhere in your code, as long as there has been no output before it.
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
It's actual location in your code is irrelevant.