vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Programming Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=188)
-   -   Verify if user is logged in for non-vb pages, using Jquery (https://vborg.vbsupport.ru/showthread.php?t=295746)

xman_79 03-03-2013 11:00 PM

Verify if user is logged in for non-vb pages, using Jquery
 
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; ?>


Princeton 03-04-2013 06:19 PM

interesting...

thanks for sharing :up:

abdobasha2004 03-04-2013 10:54 PM

nice coding, but what versions are compatible?

xman_79 03-04-2013 11:01 PM

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

ChiNa 05-25-2013 02:27 AM

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

Lee Roberts 05-27-2013 07:50 PM

Quote:

Originally Posted by ChiNa-Man (Post 2424038)

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


All times are GMT. The time now is 09:27 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.01191 seconds
  • Memory Usage 1,745KB
  • 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
  • (2)bbcode_code_printable
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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