Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 06-03-2013, 05:23 PM
kklimack kklimack is offline
 
Join Date: Jun 2013
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Show external page only if logged in

Hello, I already have external pages on a website and am looking to only show the pages if the user is logged into their vBulletin account on the same website. I am unsure what to include in PHP from vbulletin to make this happen.

Basically... if user is logged in then show page. If not, return to the standard vBulletin login form (/forum/login.php?do=login).

Any help would be appreciated!
Reply With Quote
  #2  
Old 06-03-2013, 07:55 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should really check out some of the articles for building your own vBulletin powered pages.
Reply With Quote
  #3  
Old 06-06-2013, 12:32 PM
kklimack kklimack is offline
 
Join Date: Jun 2013
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, this is a separate little app that has already been written. There is many pages and PHP functions. I really just need to know what string I would use to check if the user is logged on or not.
Reply With Quote
  #4  
Old 06-06-2013, 01:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you already including vbulletin's global.php in your external pages? If so, you just need to check for $vbulletin->userinfo['userid'] != 0, which will only be true for logged in users.

If you're not including global.php, you need to do that. The "current working directory" needs to be your forum directory (the directory that has global.php) for the include to work. So if that isn't where your external script is located, you would need to chdir() to it before the include and maybe chdir() back to the original directory if other things in your script depend on it.

Also, if your external script isn't in the vb forum directory, then for that to work your vbulletin cookie path needs to be set '/' (which I believe is the default), otherwise the vb cookies won't be sent and users won't appear logged in.

To be honest I think including global.php does more than you need to do just to check if the user is logged in. I think I remember reading a thread where someone had managed to include the file includes/init.php, which will do less unnecessary work, but I can't remember what needs to be done for that to work.
Reply With Quote
  #5  
Old 06-06-2013, 01:14 PM
kklimack kklimack is offline
 
Join Date: Jun 2013
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I figured it out. Here is the code I use if anyone else needs it.

Code:
<?php
$root_path = $_SERVER['DOCUMENT_ROOT'];
chdir($root_path."/forum/");
require($root_path."/forum/global.php");
require_once($root_path."/forum/includes/functions_login.php");
$username = $vbulletin->userinfo['username'];
$userid = $vbulletin->userinfo['userid'];
if ($userid !=0) 
    {     
    echo "Hello $username"; 
    } 
else { 
    echo "No account logged in"; 
    } 
?>
--------------- Added [DATE]1370528102[/DATE] at [TIME]1370528102[/TIME] ---------------

Thanks KH99!
Reply With Quote
Благодарность от:
Simon Lloyd
Reply

Thread Tools
Display Modes

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 07:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03747 seconds
  • Memory Usage 2,193KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (1)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete