[SOLVED] strange header problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

[SOLVED] strange header problem

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Post the true authentication php which is included.
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post by Think Pink »

you can see it in my first post
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

sample page

Post by phpScott »

How about a sample page that includes the authentication page.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Re: strange header problem

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post 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?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

[SOLVED] strange header problem

Post by Think Pink »

thx
Post Reply