there must be
session_start() before your code
have you check the $row->user, is it have value??

rgds
[xm]
http://amadarum.e-tics.net/nigritude-ultramarine.php

----- Original Message ----- 
From: "Ross Bateman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 10, 2004 12:24 PM
Subject: [PHP] $_SESSION <- Learning


> Hi
>
> I am finally starting to try and use register_globals = off on my Servers.
> This means a lot of code that has to be checked and changed.
>
> Unfortunatly I am struggeling to come to grips with this new concept (new
to
> me that is) and was wondering if anybody could give me some pointers.
>
> Getting stumped at my login script.
> Once I have checked user and passwords, I pass a few SESSION vars to use
> throughout my app.
>
> <snip>
> if ($status == 1)
>    {
>        //initiate a session
>        session_start();
>        //register session variables
>        $_SESSION['SESSION'];
>        //Get DataBase details and connect to it
>        include($root_path . "include/vars.php");
>        $query = "SELECT * FROM admin WHERE user_name = '$user'";
>        $result = mysql_query($query);
>        $row = mysql_fetch_object($result);
>        //include the username
>        $_SESSION['SESSION_UNAME'] = $row->user;
>        //include the user id
>        $_SESSION['SESSION_UID'] = $row->admin_id;
>        //set the SecLevel Session Var
>        $_SESSION['SESSION_SEC'] = $row->sec_level;
>        //Now do the redirect
>                //redirect to Admin Page
>                header("Location: ./admin_main.php");
>        exit();
>
>    }
> else
> </snip>
>
> Where ever I have the $SESSION['var_name'] I used to have a
> session_register("SESSION_VAR");
> $SESSION_VAR = $row->user;
>
> I then redirect to my app main page and check if a session is registerd to
> make sure a user is logged in:
>
> //check that each page is secure
> session_start();
> //OLD CODE IN SCRIPT = if (!session_is_registered("SESSION"))
> if(isset($_SESSION['SESSION']))
>    {
>        //if session check fails, invoke error handler
>        header("Location: ./../error.php?e=2");
>        exit();
>    }
> ?>
>
> That all works fine, but when I finaly start to display data on the main
> page, nothing shows up.
>
> One of the things I try to display is the name of the user logged in:
> From the login script
> //include the username
> $_SESSION['SESSION_UNAME'] = $row->user;
>
> then on my main page
> echo "logged in as <b>" . $_SESSION['SESSION_UNAME'] . "</b> ";
>
> Needless to say, no data is displayed..... anybody able to point out what
I
> am getting wrong here. It used to work fine before the old way with
> register_globals = on.
>
> SIDE Note:
> On a Windows PC with Apache, PHP and MySQL installed, even with the
> register_globals = on set, the SESSION vars do not work.
>
> Thanks and sorry for the long post,
>
> Ross

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

Reply via email to