I know this is a familiar error for many, usually caused by an include('somefile.php') or require_once('somefile.php') command, in which 'somefile.php' contains the header('Location: [url]http://.[/url].....') redirect. Normally, the error occurs if the redirect comes after the page has already written content, or especially if an extra blank space or line-break precedes <?php or follows ?> in either the included file or the main/parent file.
My issue is, I have the exact same code (see below) to begin several files within an admin section of a site where a password is required, however 3 of the files report the following error:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/57/8312157/html/admin/filename.php:1) in /home/content/57/8312157/html/admin/check.php on line 1
and the other four do not, properly redirecting the user to the login page. Each file begins like this:
<?php require_once('check.php'); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
(with no spaces or breaks before or after the <?php ... ?>)
where 'check.php' contains an if-then statement checking for a cookie. If the cookie exists, the page is displayed, if not, the user is redirected to the login page.
Since some of the pages do not return the error, I know 'check.php' is not the problem. After meticulously going over the first line of code in each file, making sure there are no blank spaces, I can not find any differences in the files that properly redirect to the login screen and the files that cause the error. I feel like I'm missing something really simple, but for the life of me, I can not figure it out.
Here's an example of the code working correctly:
http://www.calkain.com/admin/users.php redirects to the login screen.
I can not provide links to the problem files, as they contain sensitive client data. But I assure you, there IS NO DIFFERENCE in the first line of code in any of the files.
Has anyone ever had a similar problem? I've searched all over, and the only solutions I've come across are the "check for blank space" suggestions. I'd appreciate any help on this! Thanks very much.