Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2009, 11:23 AM
Ingenious Ingenious is offline
 
Join Date: Mar 2008
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Checking if user logged in, on external page (VERY simple version required)

Hi everyone,

I would like users of my site to be able to add comments or rate products in a part of my site that is external to VBulletin. To make this simple and prevent abuse/spam etc I would like to allow this only for forum members who are also logged in.

I am using 3.7.1 but shortly updating to 3.8.1

I've had a look over the mods and bits and bobs and there's a fair few scripts that should allow login/logout in external pages. But I want to keep it simpler than that, sending the user off to the actual forum to log in first (logic behind this, let VBulletin worry about login/paswords, cookies etc, seems more secure than me trying to do it).

All I need to do then is check in my script, which for simplicity will be in the same folder as the forum, whether someone is logged in to VBulletin.

I have seen this sort of code:

PHP Code:
// We check if user is logged in
if ($vbulletin->userinfo['userid']!=0) {
// If Logged in display welcome back message 
Am I right in thinking before that will work I need to include global.php?

If so is this the right code:

PHP Code:
require_once('global.php'); 
Do I need to worry about checking cookies, or anything else, is this all taken care of by global.php?

Finally, what would be the code to check if the user (assuming already checked they are logged in) is of a particular usergroup. Is it this:

PHP Code:
if ($vbulletin->userinfo['usergroupid'] == '6' )
    {  
etc 
The above bits were from a script that had this at the top, so the right person is credited:

Quote:
Simple vB User login and access control on non vB pages
By Bill@Billspaintball.com
Version 2.00 - March 21st, 2008
For vB 3.7.x
Apologies for asking what appears to be something really simple, I did spend a fair time in search however a lot of the stuff relates to more complicated processes and I'm not too sure what bits I need to get started.

Finally, is there a list somewhere of other user info I can get similar to $vbulletin->userinfo['usergroupid'] ie. what other info userinfo['parameter'] can be used to retrieve?

Regards,
Ingenious
Reply With Quote
  #2  
Old 03-12-2009, 02:09 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's an article on writing external pages - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. And you'll see that they include global.php and then can use the user variables and templates and such.

The condition for a usergroup would be (using usergroup 6 here):
PHP Code:
if (is_member_of($vbulletin->userinfo6)) 
or for multiple usergroups:
PHP Code:
if (is_member_of($vbulletin->userinfox,y,z)) 
Reply With Quote
  #3  
Old 03-12-2009, 02:37 PM
Ingenious Ingenious is offline
 
Join Date: Mar 2008
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your reply and that link. This has given me the confidence to try a quick PHP script, and this works a treat (I know this is basic stuff, but I am still a beginner!):

PHP Code:
<?
require_once('global.php');

if ($vbulletin->userinfo['userid']!=0) { 

echo "User is logged in</br>";
echo "Username is: ".($vbulletin->userinfo['username'])."</br>";
echo "Usergroup is: ".($vbulletin->userinfo['usergroupid'])."</br>";

if (is_member_of($vbulletin->userinfo, 5,6)){

echo "User is member of usergroup 5 or 6</br>";}

if (is_member_of($vbulletin->userinfo, 0,1)){

echo "User is member of usergroup 0 or 1</br>";}else{
echo "User is not a member of usergroup 0 or 1</br>";}

  
}else{

echo "User is not logged in! (put help and link to forum to log in here)</br>";

}
?>
If I am not logged in, it will say so. I can then log in to the forum and just refresh the page above and it shows me as logged in OK :up: (The other stuff was just testing to show it would recognise certain usergroups).

This is great as I can now restrict options and content on my site to only valid (and logged in) forum members.

JOB DONE
Reply With Quote
  #4  
Old 03-12-2009, 02:45 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good to see it worked!

Good idea to start with something basic and work from there.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:31 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05993 seconds
  • Memory Usage 2,205KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete