Posted on: 03/17/05 02:05pm
By: Anonymous (Ofey)
I'm really way out of my depth here in this forum.
But anyway, I'm trying to write a bit of php on a staic page and I wanted to know is there anyway to find out if a user is logged in or not.
Is there a global variable for the users ID. If it isn't set to null then I'd know user is logged in and registered.
Anyone have any ideas?
Regards,
Find user id
Posted on: 03/17/05 03:14pm
By: machinari
you may need to declare this global depending upon your script...
$_USER['uid'] will be '1' for anonymous, '2' for root, above 2 for logged in members.
I think I have that right.
Hope that helps
Find user id
Posted on: 03/17/05 03:23pm
By: Dirk
$_USER['uid'] may also be empty for anonymous users.
bye, Dirk
Find user id
Posted on: 03/18/05 01:48pm
By: ofey
Tried:
global $_USER['uid'];
$test =$_USER['uid'];
echo $test;
Obviously this is not how to declare global variables.
So how is it done?
(There is absolutely nothing else on the page.
I just want to get the user ID into a variable.)
Regards,
Find user id
Posted on: 03/18/05 01:56pm
By: Dirk
May I suggest reading a book or
online resource[*1] about PHP?
global $_USER;
echo $_USER['uid'];
bye, Dirk
Find user id
Posted on: 03/18/05 02:02pm
By: ofey
I know I've alot of learning to do.
So I'll get to it!
Thanks
Find user id
Posted on: 03/18/05 02:13pm
By: Anonymous (mach)
my apologies, I should have been more specific.
Find user id
Posted on: 03/18/05 02:42pm
By: ofey
Aren't global variables not defined elsewhere is geeklog. Like when someone logs in. And all I want to do is use that variable. For example just to simply echo it.
Why is it not as simple as this?
Find user id
Posted on: 03/19/05 11:14am
By: ofey
Of course global variables are defined elsewhere, but obviously must be declared wherever I want to use them.
Regards
Find user id
Posted on: 03/20/05 10:31am
By: ofey
Found exactly what I was looking for at:
here[*2]
For anyone interested, this works for me:
global $_CONF, $_USER;
print ("username={$_USER['username']}
");
print ("userid={$_USER['uid']}
");
print("remote address= {$_SERVER['REMOTE_ADDR']}
");
print("http remote address {$HTTP_SERVER_VARS['REMOTE_ADDR']}
");
print("site url= {$_CONF['site_url']}
");