[thelist] handling PHP session and logins

Steve Webster steve at netbreed.co.uk
Sat Feb 22 17:08:01 CST 2003


Hi Tom,

> I'm trying to kick a user to a login page if they have not logged in.
> I am having trouble though, with dual headers sent. I can't
> understand how to fix the logic, and I thought I had it working
> right. Maybe someone can straighten me out on a good way to do it.
> Here is what I have been doing:
>
> [SNIP]
>
>
> The problem is when they are NOT logged in, i get the "Warning:
> Cannot modify header information - headers already sent.." error.

Is the code you've given the exact code you're using? The problem you
describe sounds like normal output is being sent before your call to
header(), either by a print() or echo() statement or any sort of text
outside of the PHP tags.

In my experience, this is most often caused by whitespace before/after
the PHP tags either in the main PHP file or in any file include()ed
within the main PHP file, or by some error message being output before
the call to header().

Incidentally, I ran your code without problems so if the above doesn't
ring a bell then check your hosting provider to make sure they're not
adding anything before the PHP code runs (like some free hosts do with
banner code).

Regards,

Steve

--

================================
  Steve Webster
  Freelance Web Developer
  steve at codejunkie.co.uk

  PHP, MySQL, Flash, Perl + more
  http://www.codejunkie.co.uk
================================





More information about the thelist mailing list