Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
#312798 01/19/2007 3:59 PM
Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
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
}

// Want to create a welcome message?
if( $userob->is_logged_in ) {
if(
$userob->is_banned ) {
echo
"Go away, " . $userob->fields['USER_DISPLAY_NAME'];
} else {
echo
"Welcome, " . $userob->fields['USER_DISPLAY_NAME'];
}
} else {
echo
"Please register";
}


Note that $userob->fields is the same as the $user you've been using before, just wanted to not have two different variables hanging around

If you have any problems, it could be due to some paths being off, but the php error will explain that
Attachments
2389-user_auth.txt (7.45 KB, 184 downloads)

1 member likes this: Gizmo
Sponsored Links
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Grazie Ian thumbsup


- Allen wavey
- What Drives You?
Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
Looks awesome :), can't wait to get some time to fiddle hehe


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Joined: Dec 2002
Posts: 67
Power User
Power User
Joined: Dec 2002
Posts: 67
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 have tow domains set up like this:
www.hairfacts.com
www.hairtell.com (which is actually located at www.hairfacts.com/hairtell)

I'm trying to make people have to be logged into the forum at www.hairtell.com/forum before they can access an editing page at www.hairfacts.com/wiki

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"

Any thoughts? =)

Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
I'll bet it's the cross-domain issue.


- Allen wavey
- What Drives You?
Sponsored Links
Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
Yes, the cookies belong to one domain, security won't allow it to run on a seperate domain properly, imo

Last edited by Gizmo; 01/19/2007 8:45 PM.

UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Joined: Dec 2002
Posts: 67
Power User
Power User
Joined: Dec 2002
Posts: 67
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...

Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
As long as the URLs are properly set in the userauth.php file, and the path to said file is proper, it should work :scratches head:


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
$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.

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Originally Posted by Ian Spence
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.
Code
		//if( ! $data ) {
$this->build_permissions();
return true;
// }

Last edited by blaaskaak; 03/14/2007 11:34 AM.
Sponsored Links
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
When a user has a valid cookie file, but that account was deleted, this class also gives an error at line 78.

Code
foreach( $temp as $k => $v ) {

Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
Updated first post to address all bugs mentioned. Note that the class was renamed to work with a bug in php (it's now user_auth, not UserAuth)

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Originally Posted by Ian Spence
Updated first post to address all bugs mentioned. Note that the class was renamed to work with a bug in php (it's now user_auth, not UserAuth)

Thanks for the fixes! I use this one extensively in just about every supporting script I have running here!

Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
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 frown
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
}

// Want to create a welcome message?
if( $userob->is_logged_in ) {
if( $userob->is_banned ) {
echo "Go away, " . $userob->fields['USER_DISPLAY_NAME'];
} else {
echo "Welcome, " . $userob->fields['USER_DISPLAY_NAME'];
}
} else {
echo "Please register";
}


Warning: in_array() [function.in-array]: Wrong datatype for second argument in forums/includes/user_auth.inc.php on line 202

Whats wrong ?

Thanks for any help as always wink


BOOM 7.6.+ rocks....
Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
In my best Penelope Pit stop voice

Any one ?
Helllp


BOOM 7.6.+ rocks....
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
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.


- Allen wavey
- What Drives You?
Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
PHP Version 5.2.2

im using full paths in all instances wink


ive chopped out the full path in my example

/home/cwcom/domains/xxxxx.co.uk/public_html/forums

include ('/home/xxxxx/domains/xxxxxxxx.co.uk/public_html/forums/includes/user_auth.inc.php');


the 2 paths in the /includes folder are also correct.

require_once( "/home/xxxxx/domains/xxxxxxx.co.uk/public_html/forums/includes/config.inc.php" );
require_once( "/home/xxxxx/domains/xxxxxx.co.uk/public_html/forums/libs/mysql.inc.php" );

Last edited by Mark_S; 08/10/2007 2:02 PM.

BOOM 7.6.+ rocks....
Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
any little scripts i can try to start to debug this ?


BOOM 7.6.+ rocks....
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Good question - Ian may be your only hope, I haven't tried this one but if it works for others it should work for you.


- Allen wavey
- What Drives You?
Joined: Jan 2003
Posts: 3,456
Likes: 2
Master Hacker
Master Hacker
Offline
Joined: Jan 2003
Posts: 3,456
Likes: 2
Find:
Code
function UserAuth() {

Replace with:
Code
function user_auth() {

The constructor didn't get renamed when I renamed the class. I can't wait until Threads stops supporting PHP 4.X

Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
Originally Posted by Ian Spence
The constructor didn't get renamed when I renamed the class. I can't wait until Threads stops supporting PHP 4.X
Talked to Rick about that, he said that anything like that would be far off smirk


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Not much after Dec 31, eh? wink


- Allen wavey
- What Drives You?
Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
Originally Posted by Ian Spence
Find:
Code
function UserAuth() {

Replace with:
Code
function user_auth() {

The constructor didn't get renamed when I renamed the class. I can't wait until Threads stops supporting PHP 4.X


Done but still not working. ??

Snip it from the includes file.
PHP Code


class user_auth {
var
$fields;
var
$is_logged_in;
var
$permissions;
var
$is_banned;
var
$groups;

function
user_auth() {
global
$config, $dbh;

// First, the stupid stuff we do in every constructor




My page is test.php
PHP Code

<?php
include ('/home/xxxxx/domains/xxxxxxxxx/public_html/forums/includes/user_auth.inc.php');

// Want to create a welcome message?
if( $userob->is_logged_in ) { if( $userob->is_banned ) { echo "Go away, " . $userob->fields['USER_DISPLAY_NAME']; } else { echo "Welcome, " . $userob->fields['USER_DISPLAY_NAME']; } } else { echo "Please register<br />"; }
echo
"Script has ran. <br />";
?>


1. I am logged into my forums
2. Output = "Please register"
3. No errors out put ??

I cant understand what's wrong?

Its there a die script i can do for the sql?
To see where its failing??

Thanks for the help and assistance as always. wink


BOOM 7.6.+ rocks....
Joined: Nov 2003
Posts: 482
Enthusiast
Enthusiast
Offline
Joined: Nov 2003
Posts: 482
$userob = new user_auth();

needs to be there, before you can start using the class.. :2c:

PHP Code



<?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:

// Want to create a welcome message?
if( $muhaha->is_logged_in ) {
if(
$muhaha->is_banned ) {
echo
"*cough* be gone, " . $muhaha->fields['USER_DISPLAY_NAME'];
}
else {
echo
"Waaazzaaaap, " . $muhaha->fields['USER_DISPLAY_NAME'];
}
} else { echo
"Please register<br />";
}
echo
"Veni, vidi, vici!! <br />";
?>


of course, use 'userob' for your case. i just kinda like 'muhaha' laugh

Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
Sweet that works wink

Thanks for getting back smile

looks like i was missing the

$muhaha = new user_auth(); // w00t, yah baby :rawk:
in my protected page wink

Thanks again.
i laughed at the outputs lol


BOOM 7.6.+ rocks....
Joined: Nov 2003
Posts: 329
Beta Tester
Beta Tester
Offline
Joined: Nov 2003
Posts: 329
Will this work in 7.3 ??


BOOM 7.6.+ rocks....
Joined: Feb 2008
Posts: 11
Newbie
Newbie
Offline
Joined: Feb 2008
Posts: 11
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

Thank you


Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
This works in 7.3, except for the permission reading stuff. That has changed. If you need that, like I do, this script would have to be updated.

A query that gets a username if you only have a number is easy.

Code
select ubbt_USER_DISPLAY_NAME from ubbt_USERS where USER_ID = 50

Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Thanks Yarp! smile


- Allen wavey
- What Drives You?
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Originally Posted by blaaskaak
This works in 7.3,


FYI: It does *NOT* work. It might have when I tested it a while ago, but it doesn't work anymore now.

Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
Originally Posted by blaaskaak
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.

Joined: Sep 1999
Posts: 76
Power User
Power User
Offline
Joined: Sep 1999
Posts: 76
PHP Code
// Am I in group 3?
if( $userob->in_group( 3 ) ) {
// Why, yes we are
}

Is anyone out there using the in_group check successfully? I'm running 7.2.2 and it doesn't seem to work for me.

I've got a simple conditional check:

PHP Code
if ($userob->is_logged_in ) {
if (
in_array($userob->fields['USER_ID'], $authors)) {
// Allow specific IDs
$allow = 1;
} elseif (
$userob->in_group(5)) {
// Allow members in Group 5
$allow = 1;
} else {
// Not allowed
$allow = 0;
}
}


which fails, even though a user is part of group id 5. The individual ID check works fine though.

Joined: Jan 2000
Posts: 5,833
Likes: 20
UBBDev / UBBWiki Owner
Time Lord
UBBDev / UBBWiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,833
Likes: 20
Has anyone gotten this working (at least checking groups) in 7.3? I need something for a project I'm working on...


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, My UBB Scripts
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
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 smile

Joined: Nov 2003
Posts: 482
Enthusiast
Enthusiast
Offline
Joined: Nov 2003
Posts: 482
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 smile

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();

// Want to create a welcome message?
if( $muhaha->is_logged_in ) {
if(
$muhaha->is_banned ) {
echo
"*cough* be gone, " . $muhaha->fields['USER_DISPLAY_NAME'];
}
else {
echo
"Waaazzaaaap, " . $muhaha->fields['USER_DISPLAY_NAME'];
}
} else { echo
"Please register<br />";
}
echo
"Veni, vidi, vici!! <br />";

// 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 :)';
}
?>


Joined: Oct 2004
Posts: 14
User
User
Offline
Joined: Oct 2004
Posts: 14
This shows me all the fields|values under the "fields" array but I cant seem to dump the "groups" array.

foreach ($userob->fields as $key => $value) { print "$key $value
"; }


Last edited by swebs; 07/17/2008 6:24 PM.
Joined: Nov 2003
Posts: 482
Enthusiast
Enthusiast
Offline
Joined: Nov 2003
Posts: 482
that's because it's an array, so you'd need a nested for loop for that array wink

Joined: Oct 2004
Posts: 14
User
User
Offline
Joined: Oct 2004
Posts: 14
What do we add to this so that we get the site wrapper.

I mean I have what I want working but I would like it all to be placed in the middle section of the site?

Joined: Sep 1999
Posts: 76
Power User
Power User
Offline
Joined: Sep 1999
Posts: 76
Originally Posted by swebs
What do we add to this so that we get the site wrapper.

I mean I have what I want working but I would like it all to be placed in the middle section of the site?
Check the sticky thread titled [7.x] Generic Page Outside of forum directory in this forum.

Joined: Oct 2004
Posts: 14
User
User
Offline
Joined: Oct 2004
Posts: 14
The problem is that I have a bunch of dynamic pages that call eachother. I would have to create a bunch of wrapper pages.

Is there any way to create 1 file the I can include in my code to add the header and footer of the site?

Page 1 of 2 1 2

Link Copied to Clipboard
Donate Today!
Donate via PayPal

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.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Posts: 70
Joined: January 2007
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)