[thelist] handling PHP session and logins
Tom Dell'Aringa
pixelmech at yahoo.com
Sat Feb 22 16:47:00 CST 2003
Hi,
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:
================================================================
<?
// The following 3 variables will have been set at the login
// process page already.
session_start(); <-- this sends a header of course
$uid = $_SESSION["uid"];
$firstname = $_SESSION["firstname"];
$aid = $_SESSION["aid"];
$isAdmin = 0;
$isLoggedIn = 0;
if(isset($aid))
{
$isAdmin = 1;
}
if(isset($uid))
{
$isLoggedIn = 1;
}
// Now I check to see if they are logged in, if not - I want
// to kick them out
if($isLoggedIn == 0)
{
// not logged in
$msg = "Aaugh! You have to be logged in to access that page!";
header("Location: login.php?msg=$msg"); <-- second header
die();
}
=====================================================
The problem is when they are NOT logged in, i get the "Warning:
Cannot modify header information - headers already sent.." error.
What am I doing wrong?
Tom
?>
=====
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
http://www.pixelmech.com/
var me = tom.pixelmech.webDeveloper();
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
More information about the thelist
mailing list