> -----Original Message-----
> From: Jami [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, December 01, 2002 3:53 AM
> To: PHP General
> Subject: [PHP] Session Variables Not Being Passed
> 
> The code that I have is as such:
> 
> //header.php
> if(isset($_POST['login'])){
>   $checkuser = mysql_query("SELECT * FROM mainacct WHERE username =
> '{$_POST['username']}' AND password = '{$_POST['password']}' ",
> $connection) or die ("Couldn't find user.");
>   if (mysql_num_rows($checkuser) > 0){
>    while ($row = mysql_fetch_array($checkuser)){
>     $_SESSION['UN'] = $row['username'];
>     $_SESSION['UserLoggedIn'] = True;
>    }
>   } else {
>       header("Location:login.php");
>    exit;
>   }
> }

You're only expecting one row to be returned, right? You could test like
this:

if($row = mysql_fetch_array($checkuser))
{
  $_SESSION['UN'] = $row['username'];
  $_SESSION['UserLoggedIn'] = TRUE;
}
else
{
  header("Location: http://yourdomain.com/login.php";);
  exit();
}

You should use an absolute URI for your header() call, not a relative
one. 

> This file is then used as an include in main.php. As long as the
variables
> are used ONLY in the header.php file, it works. But when I try to call
the
> session variables in main.php, it doesn't show the values of UN or
> UserLoggedIn. session_start() is called in main.php. Is this a quirk
with
> sessions, or is there something more I am supposed to be doing?
Running
> Apache 2 w/PHP 4.2.3 on WindowsXP.

Well, Apache 2 and PHP aren't stable together yet. It's not recommended
you use them together and that could be causing your problem.

Are you including this file before or after session_start()? If you call
session_start(), include the above code, and then $_SESSION['UN'] is not
available later in the main.php page, then it's a bug...

---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to