For a PHP redirect via header() call to succede it has to precede any page output, i.e. come before any other header(), print or echo statements. For example this will work.
while this will not:
If you already have output something on the page, you should redirect via Javascript like this: