vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Checking if user logged in, on external page (VERY simple version required) (https://vborg.vbsupport.ru/showthread.php?t=208102)

Ingenious 03-12-2009 11:23 AM

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

Lynne 03-12-2009 02:09 PM

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


Ingenious 03-12-2009 02:37 PM

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

Lynne 03-12-2009 02:45 PM

Good to see it worked!

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


All times are GMT. The time now is 06:13 PM.

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.01073 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete