1
skiseiju
get session's problem
  • 2005/3/17 12:40

  • skiseiju

  • Just popping in

  • Posts: 3

  • Since: 2005/3/17


i'v create a new page for some user,it's use for manage in someway.
but,i'v read xoops's code in checklogin.php and user.php,i can't find whitch way XOOPS use?(cookie or session?)
and, i can find the variable save this information that i can use to passing my own page.

in my page,i have to do something:
1.identify this user is xoops's user(but user have log-in in xoops's index.php)
2.check this user's level is over level5
3.query some data from database.


can anyone help?

Thnks a lot!

2
ackbarr
Re: get session's problem

//To access XOOPS global variables, you need to include mainfile.php
//Change to path to mainfile.php
include('mainfile.php');

//Check if the current request comes from a XOOPS user
if ($xoopsUser) {
  
//Person logged in
} else {
  
//Person not logged in
}

$minUserLevel 5;

//Check the current user's level
if ($xoopsUser->getVar('level') >= $minUserLevel) {
  
//User is at the correct level
} else {
  
//User is not at the correct level
}

//Get real db table name (adds XOOPS db table prefix)
$tblName $xoopsDB->prefix('tablename');

//Make a database query
$sql "SELECT * FROM $tblName";
$ret $xoopsDB->query($sql);

//Loop through query results
while ($arr $xoopsDB->fetchArray($ret)) {
  
//Do something with each row returned
  
echo($arr['field1']);
}


One word of caution though. If you are trying to use the level check to determine if the current user is an administrator, it will not work as expected. Only the admin user created during install will have a level of '5'.

A better way would be to check the user's group membership:
$groups $xoopsUser->getGroups();

if (
in_array(XOOPS_GROUP_ADMIN$groups)) {
  
//User is in the administrators group
}

3
skiseiju
Re: get session's problem
  • 2005/3/17 15:03

  • skiseiju

  • Just popping in

  • Posts: 3

  • Since: 2005/3/17


It's really works!Thank you very much!

but i have another question...

if i login as 'ABC',and i transfer to the page i made,named 'manage.php'.i can check the user is xoops's user.When i echo (xoopsUser),it shows:

-------------------------------
code:
if ($xoopsUser) {
echo ("HI~$xoopsUser");
} else {
echo ("Sorry,NoPermission!");
}
-------------------------------

but it shows in web:


-------------------------------
HI~ Object
-------------------------------


If i want to query some data using this user's id,like:


select *
from members
where id='xoops user's id'

what should i fix this code?



Thanks again!

4
ackbarr
Re: get session's problem

as you found out $xoopsUser is an object. To be exact, it is an instance of the XoopsUser class. To access properties of the $xoopsUser object there are two handy functions:

$xoopsUser->getVar('varname');
$xoopsUser->setVar('varname', 'value');

each database field can be accessed through these two functions. So if the information you want to access is in the 'uid' database field:
$uid $xoopsUser->getVar('uid');


in your two specific examples there are 3 different fields you may be interested in:

$xoopsUser->getVar('uname'); //The login name for the current user
$xoopsUser->getVar('name'); //The name of the current user (optional)
$xoopsUser->getVar('uid'); //The id of the current user

5
ackbarr
Re: get session's problem

I'd recommend that to learn more about XOOPS add-on/module development that you check out http://dev.xoops.org which is a resource for module developers that includes:

1. Development Documentation (in a wiki)
2. Developer forums
3. Project tools to manage the development of XOOPS modules
4. Code snippet libraries

Login

Who's Online

142 user(s) are online (43 user(s) are browsing Support Forums)


Members: 0


Guests: 142


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits