Page 1 of 1

[SOLVED] strange header problem

Posted: Mon Sep 20, 2004 11:23 pm
by Think Pink
hello,
I have a strange problem with my script, it send's an error thet header are allready sent. There is not any output, echo, space bla bla before the header.

I say is strange because this actually works if in all my scripts I put session_start();

but the problem is that the script should be on a password protected area.
so if I include in each file authentication.php than it stoppes working and gives me the header problem.

the authentication is something like this:

Code: Select all

<?php
session_start();

if(!isset($_SESSION['admin'])){
header ("location: logout.php");
exit;
}

if(!isset($_SESSION['password'])){
header ("location: logout.php");
exit;
}


if((time() - $_SESSION['timestamp']) > 30){
header ("location: logout.php");
exit;
}
else{
$_SESSION['timestamp'] = time();
}
?>
Any ideeas?
Thx

Posted: Tue Sep 21, 2004 2:45 am
by CoderGoblin
The error message normlly means that you have output something already. The php Header command MUST be before any output. It is a common mistake to include something which outputs something without realising it.

Posted: Tue Sep 21, 2004 3:28 am
by Think Pink
yes I know about the output, and as I said I checked and there is no output, echo, space - before header.

the thing is that if I use session_start(); insted of including authentication.php (wich contains session_start();) works great.

Do you have an answer for that?
Thx

Posted: Tue Sep 21, 2004 3:44 am
by CoderGoblin
Post the true authentication php which is included.

Posted: Tue Sep 21, 2004 5:32 am
by Think Pink
you can see it in my first post

sample page

Posted: Tue Sep 21, 2004 5:43 am
by phpScott
How about a sample page that includes the authentication page.

Re: strange header problem

Posted: Tue Sep 21, 2004 5:58 am
by CoderGoblin
Think Pink wrote: the authentication is something like this:
Whilst I realise that the code above should help us track the problem down, the fact is that as the code stands it should work.. so we need additional information. Help us to help you.

Can you show us the main file.

Are you sure you have no blank lines before or after the php blocks anywhere in files which the authentication code is included ?

Posted: Tue Sep 21, 2004 6:12 am
by feyd

Posted: Tue Sep 21, 2004 7:49 am
by Think Pink
ok, problem solved. Thx guys very much for your help.
After all the problem was ME.
After the php closing tags in authentication.php I had few spaces.

something like this
<?php
line1.
line2...........
line54.
line55
?>
line56
...


PS how do I SOLVE a thread?

Posted: Tue Sep 21, 2004 7:57 am
by CoderGoblin
Header problems are often difficult to track down due to having to find rogue characters like that. I think we have all been there :wink:

To change to solved...
Simply change the Subject line in a post...
Only the creator (you in this case), or a moderator (at a guess) can do it.

[SOLVED] strange header problem

Posted: Tue Sep 21, 2004 8:08 am
by Think Pink
thx