[thelist] handling PHP session and logins

CV cervantes_vive at yahoo.com
Sat Feb 22 21:16:49 CST 2003


This is similar to how I do it & I dont have problems.

It has happened tho that sometimes I accidentally
leave a space or a tab in front of the <?php

C

--- Tom Dell'Aringa <pixelmech at yahoo.com> wrote:
> 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/
> --
> * * Please support the community that supports you.
> * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip
> Harvester
> and archives of thelist go to:
> http://lists.evolt.org
> Workers of the Web, evolt !


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/



More information about the thelist mailing list