header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. And in your case, you are using echo before header()