Attached is the file. Rename it user_auth.inc.php and throw it in the includes directory of your forums.
Then just require the file and use it as follows
PHP Code
// Usage:
$userob = new user_auth();
// Am I logged in? if( $userob->is_logged_in ) { // I am logged in }
// Am I in group 3? if( $userob->in_group( 3 ) ) { // Why, yes we are }
// Who cares what group I'm in! I wanna know // if I can read a topic from forum 7 if( $userob->check_access( 7, "read" ) ) { // Apparently I can }
// What if I want to know if I'm an administrator if( $userob->fields['USER_MEMBERSHIP_LEVEL'] == "Administrator" ) { // That means I'm teh uber user }
Hi, thanks for the code! As usual, I'm trying to do something weird with things and have a little prob:
I get this error message: Fatal error: Cannot instantiate non-existent class: userauth in /home/XXXX/public_html/wiki/extensions/ubbt_auth_mod.php on line 24
I know usually this wouldn't work cross-domain, but since hairtell.com is actually a folder inside hairfacts.com, I thought it might work. It actually includes the files, and recognizes the sql class, but dies on the "userauth" class. I also don't know why it's showing "userauth" in lowercase letters in the error message, since it's declared and called like "UserAuth"
The cookies are an issue, definitely. I wonder why it's seeing the UserAuth class as non-existant, though. Its existance wouldn't be tied to a cookie issue...
$userob = new UserAuth(); appears before line 24 in public_html/wiki/extensions/ubbt_auth_mod.php ?
The error message returning the class name in lowercase is a PHP bug which has been fixed I think in the latest PHP. So I don't think that's your problem.
if( $userob->check_access( 7, "read" ) ) { // Apparently I can
The authentication works like a charm, but I do have troubles with this one.
It worked yesterday evening, and suddenly stopped working. After puzzling around for a while, finally it was fixed by updating the permissions from the control panel.
No changes or anything, just hit the update button.
Edit: It happened again. I commented out the caching check and it seems to work stable now.
Now here is a surprise ! Its not working for me? It seems that its not picking up on $userob.
File saved and uploaded into forums/includes folder as user_auth.inc.php Paths updated New file with simple test code
PHP Code
file test-auth.php <?php include ('forums/includes/user_auth.inc.php'); echo "test auth <br />";
$userob = new user_auth();
// Am I logged in? if( $userob->is_logged_in ) { echo "you are logged in"; }
?>
Out put only my first test echo of test auth
If i'm logged in or not the result is the same? ive tried full paths and relative paths If they are wrong i do get the php error so they are correct. Humm what could be wrong?
Help << i'm stuck.
Aso if i run the file with all of the examples in the first post, i get this error which made me use the test text.
Quote
$userob = new user_auth();
// Am I logged in? if( $userob->is_logged_in ) { // I am logged in }
// Am I in group 3? if( $userob->in_group( 3 ) ) { // Why, yes we are }
// Who cares what group I'm in! I wanna know // if I can read a topic from forum 7 if( $userob->check_access( 7, "read" ) ) { // Apparently I can }
// What if I want to know if I'm an administrator if( $userob->fields['USER_MEMBERSHIP_LEVEL'] == "Administrator" ) { // That means I'm teh uber user }
hmmm, it could use some 'or die' statements to show where it's failing, tho I guess if it doesn't print any of them none of them are working.
I would first double-check the path/url posted to the top - some servers want full paths/urls to the include file, not a relative one - this could be why it's not printing any results.
For chat integration, the chat should be able to call up the ubb profile of a user.
This is complicated by the fact that these are not organized by user name but by number.
Can you please post a conversion routine from user name to user number? Or a routine that outputs the profile but uses user name as input? Or even better, both of the above?
I post this here in the midst of this thread, as this is intrinsically related to user authentication, and actually a by-product of the user authentication code. Whoever needs user authentication for an external product like a chat could use a user profile link.
And like Mark_S, I am curious if all this will work for 7.3
FYI: It does *NOT* work. It might have when I tested it a while ago, but it doesn't work anymore now.
okay, got it working again. If you are in desperate need for it, pm me, since my fixes are far from neat. I just plunged through it and tried stuff till I got it working.
Also, the forum permissions stuff is all disabled in my fix.
I've got it working in 7.3, but I did not implement group checking yet. I only need it in one homemade script, and just made a query in that specific script.
PHP Code
$query = " select count(USER_ID) from ubbt_USER_GROUPS where USER_ID = ? and GROUP_ID in ( SELECT GROUP_ID FROM ubbt_FORUM_PERMISSIONS WHERE FORUM_ID = ? AND READ_TOPICS > 0 ) "; $sth = $dbh -> do_placeholder_query($query,array($myuserid,$board),__LINE__,__FILE__); list($access) = $dbh->fetch_array($sth);
if (!$access) { echo "SeeYa";exit; }
I am converting most of my scripts to the ubb environment where authentication and group checking is done for me
as long as you include user.inc.php in your user auth dude, the code would be
PHP Code
$yarp = new user(); // only needs to be done 1 time if (!$yarp->check_access('forum','READ_TOPICS',$board)) { echo 'Ciao bella!'; exit; } if ($yarp->check_access('site','CAN_USE_ARCADE')) { echo 'w00t! and arcade :)'; }
reason for $userobaxx is that $userob is prolly in use for the user_auth dealio
so to modify my original post a bit:
PHP Code
include ('../libs/forums/includes/user.inc.php'); include ('../libs/forums/includes/user_auth.inc.php');
// Instantiate the user auth class as muhaha, for example $muhaha = new user_auth(); // w00t, yah baby :rawk: $yarp = new user();
// New perm crapola goes here :) if (!$yarp->check_access('forum','READ_TOPICS',$board)) { echo 'Ciao bella!'; exit; } if ($yarp->check_access('site','CAN_USE_ARCADE')) { echo 'w00t! and arcade :)'; } ?>
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.