Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
Verify if user is logged in for non-vb pages, using Jquery
xman_79's Avatar
xman_79
Join Date: Jun 2006
Posts: 65

 

Romania
Show Printable Version Email this Page Subscription
xman_79 xman_79 is offline 03-03-2013, 11:00 PM

1 - vbconnect.php
PHP Code:
<?php
chdir
('./YOUR_FORUM_FOLDER_NAME');
define('CVD', (($getcwd getcwd()) ? $getcwd '.'));
require_once(
CVD '/global.php');

$vbulletin->input->clean_array_gpc('p', array('ajax' => TYPE_BOOL));

if(
$vbulletin->GPC['ajax'] == true)    
{
    
$result = array(
        
'username' => $vbulletin->userinfo['username'],
        
'userid' => $vbulletin->userinfo['userid'],
        
'userpost' => $vbulletin->userinfo['posts'],
     );
    echo 
json_encode($result);
}
?>
2- jquery_cookie.js
Create this file using the code from this page

3- jquery_vbulletin.js
Change XXX with any another prefix wich do you want
Code:
$(document).ready(function () 
{
    $.ajax({
        url:'vbconnect.php',
        type:'POST',
        data:'&ajax=1',
        cache:false,
        async:false,
        dataType:'json',
        success:function(result){
            $.cookie('XXXuserid', result['userid'], { expires: 7, path: '/' });
            $.cookie('XXXusername', result['username'], { expires: 7, path: '/' });
            $.cookie('XXXuserpost', result['userpost'], { expires: 7, path: '/' });},
        error:function(){
            $.cookie('XXXuserid', '', { expires: 7, path: '/' });
            $.cookie('XXXusername', '', { expires: 7, path: '/' });
            $.cookie('XXXuserpost', '', { expires: 7, path: '/' });}
    })
});
4- In your php file (external file and not in directory of the forum)
Change XXX with your prefix using in jquery_vbulletin.js file
PHP Code:
<?php

$vb_userid    
$_COOKIE['XXXuserid'];
$vb_username  $_COOKIE['XXXusername'];
$vb_userpost  $_COOKIE['XXXuserpost'];

if(
$vb_userid)
{
    
// The guest is logged in 
    // Exemple
    
$output "Welcome $vb_username";
}
else
{
    
// The guest is not logged in 
    // Exemple
    
$output "Welcome " $_SERVER['REMOTE_ADDR'] . " , you are not connected to the forum";
}

?>
5- Your output (html / php)
Code:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="your/path/to/javascript/directory/jquery_cookie.js"></script>
<script src="your/path/to/javascript/directory/jquery_vbulletin.js"></script>
<?php echo $output; ?>
Reply With Quote
  #2  
Old 03-04-2013, 06:19 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

interesting...

thanks for sharing :up:
Reply With Quote
  #3  
Old 03-04-2013, 10:54 PM
abdobasha2004's Avatar
abdobasha2004 abdobasha2004 is offline
 
Join Date: Aug 2008
Posts: 541
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nice coding, but what versions are compatible?
Reply With Quote
  #4  
Old 03-04-2013, 11:01 PM
xman_79's Avatar
xman_79 xman_79 is offline
 
Join Date: Jun 2006
Location: Romania
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@Princeton: with pleasure
@abdobasha2004: vb3 - vb4
--> for vb5 I don't have this version but I think it is the same. You can do a simple test only with vbconnect.php (with little modification)

PHP Code:
<?php
chdir
('./YOUR_FORUM_FOLDER_NAME');
define('CVD', (($getcwd getcwd()) ? $getcwd '.'));
require_once(
CVD '/global.php');

$result = array(
    
'username' => $vbulletin->userinfo['username'],
    
'userid' => $vbulletin->userinfo['userid'],
    
'userpost' => $vbulletin->userinfo['posts'],
    );
echo 
json_encode($result);
?>
Go to www.yourdomain.com/vbconnect.php and see the result
Reply With Quote
  #5  
Old 05-25-2013, 02:27 AM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
4- In your php file (external file and not in directory of the forum)
Change XXX with your prefix using in jquery_vbulletin.js file



Hello,
If you could please explain about part 4?

I dont really understand if I should create a php file or where its located if there is one! Thank you very much in advance
Reply With Quote
  #6  
Old 05-27-2013, 07:50 PM
Lee Roberts's Avatar
Lee Roberts Lee Roberts is offline
 
Join Date: Jun 2008
Location: UK
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ChiNa-Man View Post

Hello,
If you could please explain about part 4?

I dont really understand if I should create a php file or where its located if there is one! Thank you very much in advance
This would be the file you create, as this is about working with external pages, note the bit that reads "(external file and not in directory of the forum)". This would be the page/file you want to do something like this in:

// The guest is logged in
}
else
{
// The guest is not logged in

.Me
Reply With Quote
Reply

Thread Tools

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 10:47 AM.


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.04396 seconds
  • Memory Usage 2,265KB
  • Queries Executed 19 (?)
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
  • (2)bbcode_code
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (1)post_thanks_box_bit
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (6)post_thanks_postbit_info
  • (5)postbit
  • (6)postbit_onlinestatus
  • (6)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
  • 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
  • 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