Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 12:08 am EST

Geeklog Forums

Find user id


Ofey

Anonymous
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,
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
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. Wink
Hope that helps
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
$_USER['uid'] may also be empty for anonymous users.

bye, Dirk
 Quote

Status: offline

ofey

Forum User
Full Member
Registered: 03/18/05
Posts: 213
Location:Dublin, Ireland
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,
Those who say it can't be done, are usually interrupted by others doing it.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
May I suggest reading a book or online resource about PHP?

global $_USER;
echo $_USER['uid'];

bye, Dirk
 Quote

Status: offline

ofey

Forum User
Full Member
Registered: 03/18/05
Posts: 213
Location:Dublin, Ireland
I know I've alot of learning to do.
So I'll get to it!
Thanks
Those who say it can't be done, are usually interrupted by others doing it.
 Quote

mach

Anonymous
my apologies, I should have been more specific.
 Quote

Status: offline

ofey

Forum User
Full Member
Registered: 03/18/05
Posts: 213
Location:Dublin, Ireland
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?

Those who say it can't be done, are usually interrupted by others doing it.
 Quote

Status: offline

ofey

Forum User
Full Member
Registered: 03/18/05
Posts: 213
Location:Dublin, Ireland
Of course global variables are defined elsewhere, but obviously must be declared wherever I want to use them.
Doh! - that was a mistake
Regards

Those who say it can't be done, are usually interrupted by others doing it.
 Quote

Status: offline

ofey

Forum User
Full Member
Registered: 03/18/05
Posts: 213
Location:Dublin, Ireland
excited
Big Celebration
Found exactly what I was looking for at:
here

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']}
");

Big Celebration Very Happy
Those who say it can't be done, are usually interrupted by others doing it.
 Quote

All times are EST. The time is now 12:08 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content