vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.7 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=228)
-   -   Integration with vBulletin - Deluxe vB User login and access control on non vB pages (https://vborg.vbsupport.ru/showthread.php?t=173698)

Billspaintball 03-20-2008 10:00 PM

Deluxe vB User login and access control on non vB pages
 
Hack Description

This is the deluxe version of the user authentication and access control system I use on the non vB pages on my website.
For the simple no frills version [URL=https://vborg.vbsupport.ru/showthread.php?t=173693look here.[/URL]

This uses the vB 3.7 login system to log you in and out. It allows you to move between your forums and other pages on your site while remaining logged in.

It allows you to do things such as restrict pages by usergroup, display different content depending on a user being logged in or not.
For example, you can have banner Adds displying to non members only, and/or let members access to specific content.

It also displays the logged in users Avatar, number of unread PM's, New posts since last visit, total posts and total threads.
It also allows you to specify a maximum Avatar size, and resize any avatars larger than that, while keeping their height/width ratios in proportion!
Its very handy if you allow large avatars, but want a small format display on your non forum pages.

If the user is not logged in, a login box is displayed, along with total posts and total threads in the forums.

I will try and offer support, but work and family commitments mean I dont have much free time.

This code is a mix of my own, and pieces I have used from other hacks that are floating around.


This script has been confirmed as working on
  • vB 3.7 RC1

Known Bugs
Will not display Avatars correctly if they are kept in the file system (database avatars are fine)

Change log

Version 3.00 (21st March 2008)
  • Initial release for vB 3.7.x


Click on Install
If you have this script installed then please click on the install link because;
  • You will get notified if any security issues are reported.
  • You will get notified when there are any upgrades to this script
  • It gives me a warm fuzzy feeling and motivates me to develop more :)

Donations
First of all, to be clear. This script is 100% free.

However if you feel an urge to donate I'm not going to say no. :)
Donations can be made at http://www.billspaintball.com/vb3/bd_donate.php

Billspaintball 03-21-2008 11:14 AM

Usage

The hack is pretty useless without some usage instructions so here they are.

You can resize avatars, keeping them to their origional proportions to make them fit your prefered layout.
For instance, if you are using a fixed width column layout.
Do this by editing lines 5 and 6 in login_inc.php
These values are in pixels.

We can use conditionals to hide or display depending on a number of things such as
Logged in or out status,
or restrict to members of a specific usergroup.

We do this by using conditionals in php tags where the normal content of a webpage would go.


If you want something only accessable to a certain usergroup, use this code in your webpage. This example is only visible to members of usergroup 6.
PHP Code:

<?php
if ($vbulletin->userinfo['usergroupid'] == '6' )
    {
    echo 
"This is only visible to people in usergroup 6";}
    
?>

You can use a simple variation of this to restrict entire pages to a certain usergroup.
For example,
PHP Code:

<?php
if ($vbulletin->userinfo['usergroupid'] == '6' )
    {
    echo 
"Have stuff for here";
             } else {
             echo 
"You do not have permission for this page"; }
    
?>


Another use is to display different content to users depending on if they are logged in or not. For example
PHP Code:

<?php
If ($vbulletin->userinfo['userid']!=0)
    {    
    echo 
"Your logged in so we can display this";
    } else {
    echo 
"Your not logged in so we display this";
    }
?>

Another use is to restrict advertising to people who are not logged in.
For example
PHP Code:

<?php 
if ($vbulletin->userinfo['userid'] <1) { echo"add code stuff goes here"; } 
?>

Of course you can play around with conditionals to do a whole range of things, these are just brief example snippets.



Troubleshooting

If your reading this chances are you are having problems.

Here are some common causes and fixes.
  1. Headers already sent or cookies already sent errors. Chances are that there is something, even just a space before the 4 lines of code in part 1. Edit this and ensure that there are no spaces before it.


  2. Path problems are the next biggest problem. Your paths must be exact else it will not work. Double check that all paths are correct.
    If you are unsure what the path is place the following code in a page all by itself.
    PHP Code:

    <?php 
    echo getcwd(); 
    ?>

    Name this file something like path.php then upload it to your website, browse to it and it will show you the exact path to your sites root.


  3. Appears to login ok, but wont show you as logged in
    Often caused by the vB cookie path setting.
    To fix log into you vB admin area;
    Code:

    AdminCP -> vBulletin Options -> Cookies and HTTP Header Options -> Path to Save Cookies

    Change

    'Suggested Settings' dropdown from '/forums/' to '/' or 'yourdomain.com'


  4. Subdomains and cross site logins
    This is a known issue with many scripts (not just this one), sometimes fixable sometimes not. Its caused by vB, PHP and your hosts security measures.

    First change your "cookie domain" settings.
    vB Admin > Control Panel > Cookies and HTTP Header Options > Cookie Domain
    Change it from being blank to
    PHP Code:

    .yourdomain.com 

    You may need to set a post referrer in your whitelist.
    vB Admin > Control Panel > General Settings > Post Referrer Whitelist
    Instructions on what to enter are listed where you change this setting.

    That should fix it if your forum is a subdomain.

    If that fails then,
    Open your /forum/login.php file and look for this code:
    PHP Code:

    error_reporting(E_ALL & ~E_NOTICE); 

    Below that add
    PHP Code:

    define('SKIP_REFERRER_CHECK'true); 

    Now save this and overwrite the file on the server with this one.

    A further reported work around is to make a copy of the required Forum Forum files on your second Server. Then you must set in the config.php on the second server to use the ip of the server with which the VB-Database is running.


  5. 404 Error on expiring passwords
    Cause - When redirected for expired password you are redirected to the directory that your login script is located in, not your forums root.

    Fix - Edit phrase called
    Code:

    passwordexpired
    Your current phrase should be
    Code:

    Your password is {1} days old, and has therefore expired.<br />
    <br />
    Please change your password using <a href="profile.php?{2}do=editpassword">this page</a>.

    change it to

    Code:

    Your password is {1} days old, and has therefore expired.<br />
    <br />
    Please change your password using <a href="../forums/profile.php?{2}do=editpassword">this page</a>.

    where ../forums/ is your forums directory.


  6. Still got problems?
    It may be a conflict with somthing already in your site.
    To check this we can just make a simple page.
    Call it test.php and use just this code in it.
    (Make sure there is no whitespace before the 1st line)
    PHP Code:

    <?php
    $curdir 
    getcwd ();
    chdir('/path/to/your/forums');
    require_once(
    '/path/to/your/forums/global.php');
    chdir ($curdir);
    ?>
    <html> 
    <body> 
    This is a heading<br /> 
    This is some more stuff <br /> 
    And another line<br /> 
    You get the idea<br /> 
    Just place stuff as you normally would with HTML<br /> 
    I use CSS to style and position on my site fwiw<br /> 
    <br /> 
    How about we put the login box right under here?<br /> 
    <br /> 
    <?php 
        
    require_once('/path/to/your/login_inc.php'); 
    ?> 
    </body> 
    </html>

    Naturally, change paths to fit your forums, then upload it.
    Browse to it and run it.

KURTZ 03-21-2008 11:17 AM

Hi Bill, some shots?

Billspaintball 03-21-2008 11:30 AM

Quote:

Originally Posted by KURTZ (Post 1470628)
Hi Bill, some shots?

Added.
See the screenshots section above.

KURTZ 03-21-2008 11:48 AM

Quote:

Originally Posted by Billspaintball (Post 1470642)
Added.
See the screenshots section above.

thx :)

NeuroLancer 03-21-2008 11:54 AM

This is really easy to configure and use, its working great right out of the box, thanks.

Hornstar 03-21-2008 10:05 PM

Just wondering if you are working on this bug, or if it is not possible: Will not display Avatars correctly if they are kept in the file system (database avatars are fine)

Billspaintball 03-21-2008 10:38 PM

Quote:

Originally Posted by hornstar1337 (Post 1471117)
Just wondering if you are working on this bug, or if it is not possible: Will not display Avatars correctly if they are kept in the file system (database avatars are fine)

Not actively.
I did try and get around it in the past, but never came up with a workable solution.

projectego 03-21-2008 11:03 PM

[high]* projectego clicks install :)[/high]

snunhuck 03-22-2008 08:10 PM

Adding PHP Code:

PHP Code:

<?php
$curdir 
getcwd ();
chdir(http://community.thinkteen.co.uk);
require_once('http://community.thinkteen.co.uk/global.php');
chdir ($curdir);
?>

breaks the page's layout.

Example here:

http://members.thinkteen.co.uk (original page)
http://members.co.uk/m2.php (Page broken + no login box)

Billspaintball 03-22-2008 09:30 PM

Try changing
PHP Code:

chdir(http://community.thinkteen.co.uk); 

to
PHP Code:

chdir('http://community.thinkteen.co.uk'); 



Quote:

Originally Posted by snunhuck (Post 1471925)
Adding PHP Code:

PHP Code:

<?php
$curdir 
getcwd ();
chdir(http://community.thinkteen.co.uk);
require_once('http://community.thinkteen.co.uk/global.php');
chdir ($curdir);
?>

breaks the page's layout.

Example here:

http://members.thinkteen.co.uk (original page)
http://members.co.uk/m2.php (Page broken + no login box)


snunhuck 03-23-2008 03:45 AM

still broken :(

C.Birch 03-23-2008 02:08 PM

Quote:

Originally Posted by Billspaintball (Post 1472001)
Try changing
PHP Code:

chdir(http://community.thinkteen.co.uk); 

to
PHP Code:

chdir('http://community.thinkteen.co.uk'); 


Should that not be a server path and not a address? eg it should be '/home/username/public_html/

snunhuck 03-23-2008 04:27 PM

hmm, I'll see if it works :)

PHP Code:

<?php
$curdir 
getcwd ();
chdir('/home86a/sub005/sc46797-PRWR/community');
require_once(
'/home86a/sub005/sc46797-PRWR/community/global.php'); 
chdir ($curdir); 
?>

Nope :( Still broken.

here's the page I'm trying to implement: http://members.thinkteen.co.uk/m2.html It's meant to look like this: http://members.thinkteen.co.uk

Billspaintball 03-24-2008 11:53 AM

Quote:

Originally Posted by snunhuck (Post 1472571)

here's the page I'm trying to implement: http://members.thinkteen.co.uk/m2.html

This mod only works with php pages, not html pages.

snunhuck 03-24-2008 01:52 PM

Good point - I forgot to do it :) and here's the new error:

Warning: getimagesize() [function.getimagesize]: Unable to access /mounted-stoarage/home86a/sub005/sc46797-PRWR/community/image.php?u=1 in /mounted-storage/home86a/sub005/sc46797-PRWR/members/login_inc.php on line 35

Warning: getimagesize(/mounted-stoarage/home86a/sub005/sc46797-PRWR/community/image.php?u=1) [function.getimagesize]: failed to open stream: No such file or directory in /mounted-storage/home86a/sub005/sc46797-PRWR/members/login_inc.php on line 35

The forum URL is http://community.thinkteen.co.uk - (aka. on a subdomain)

thegabriel 03-24-2008 07:18 PM

Hi,

I had implemented this code and it was working fine. My password had presently expired and my homepage looks scrambled. It is not redirecting to the forum page where it shows password expiry message.

If I go to the forums page, by typing http://www.example.com/forums then the message shows up.

Can you please guide me on how I could rectify this error?

Thanks,
G

Billspaintball 03-25-2008 05:21 AM

Quote:

Originally Posted by thegabriel (Post 1473537)
Hi,

I had implemented this code and it was working fine. My password had presently expired and my homepage looks scrambled. It is not redirecting to the forum page where it shows password expiry message.

If I go to the forums page, by typing http://www.example.com/forums then the message shows up.

Can you please guide me on how I could rectify this error?

Thanks,
G

Part 5 of the troubleshooting guide should help here.
https://vborg.vbsupport.ru/showpost....23&postcount=2

thegabriel 03-25-2008 11:53 AM

Hi,

Which program has this word "passwordexpired"? I am using VB version 3.6.8.

Please help.

Thanks,
G

thegabriel 03-25-2008 01:21 PM

Quote:

Originally Posted by thegabriel (Post 1474099)
Hi,

Which program has this word "passwordexpired"? I am using VB version 3.6.8.

Please help.

Thanks,
G

Just found where the phrase was ....
It was in the table vb_phrase (phrase_id = 101362)
:)

txsbmw 03-25-2008 02:48 PM

Anyone know how to make this code validate with:
http://validator.w3.org/
under XHTML 1.0 Transitional?

Almost all of my errors are coming from this one mod on my non vb pages.

davide101 04-01-2008 03:47 PM

I have two tips for anyone using this system.

First, it's to change the wording of the private messages phrase to anything you want. I have it set to say "Private messages, "1 new message", and "2 new messages". Here's the code for that (it goes in the include):

Code:

// Display PM Details and generate link to PM box
$pmremove = array("Unread ", "<strong>", "</strong>");
$unreadPM = str_replace($pmremove,"",$vbphrase[unread_x_nav_compiled]);
if ($unreadPM==1) {
        echo "<a id=\"unreadpm\" href=\"".$forumpath."private.php?$session[sessionurl] \">1 new message</a>";
} else {
        if ($unreadPM>1) {
        echo "<a id=\"unreadpm\" href=\"".$forumpath."private.php?$session[sessionurl] \">" . $unreadPM . " new messages";
  } else {
    echo "<a href=\"".$forumpath."private.php?$session[sessionurl] \">Private Messages</a>"; 
        }
}

Similarly, it's easy to show new posts with the proper grammatical syntax. In other words, have it say 'No new posts' '1 new post' or '2 new posts'.

Code:

// finds number of new posts
$newposts = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "post AS post " . iif($vbulletin->options['threadmarking'], 'LEFT JOIN ' . TABLE_PREFIX . 'threadread AS threadread ON (threadread.threadid = post.threadid AND threadread.userid = ' . $vbulletin->userinfo['userid'] . ')') . " WHERE dateline >= " . $vbulletin->userinfo['lastvisit'] . iif($vbulletin->options['threadmarking'], ' AND dateline > IF(threadread.readtime IS NULL, ' . (TIMENOW - ($vbulletin->options['markinglimit'] * 86400)) . ', threadread.readtime)'));
$newposts = vb_number_format($newposts['count']);

if ($newposts < 1) {
echo "<a href=\"".$forumpath."search.php?$session[sessionurl]do=getnew\">No new posts</a><br />";}

if ($newposts == 1) {
echo "<a href=\"".$forumpath."search.php?$session[sessionurl]do=getnew\">$newposts new post</a><br />";}

if ($newposts > 1) {
echo "<a href=\"".$forumpath."search.php?$session[sessionurl]do=getnew\">$newposts new posts</a><br />";}

Hope this helps someone. It took me a little bit of tinkering to get it just right.

Triky 04-04-2008 12:03 PM

I can't get it work.

Quote:

Notice: Undefined index: HTTPS in c:\programmi\easyphp1-8\www\vbtest\includes\class_core.php on line 1643

Notice: Undefined index: HTTPS in c:\programmi\easyphp1-8\www\vbtest\includes\class_core.php on line 1643

Notice: Undefined index: HTTP_REFERER in c:\programmi\easyphp1-8\www\vbtest\includes\class_core.php on line 1670




Unable to add cookies, header already sent.
File: c:\programmi\easyphp1-8\www\vbtest\includes\class_core.php
Line: 1643




davide101 04-10-2008 08:30 PM

Does anyone know how to access the profile url? It's not located in $vbulletin->userinfo and I'm sure where else to look. I'd like to link the avatar there.

Billspaintball 04-27-2008 05:39 AM

Quote:

Originally Posted by davide101 (Post 1480120)
I have two tips for anyone using this system.

First, it's to change the wording of the private messages phrase to anything you want. I have it set to say "Private messages, "1 new message", and "2 new messages". Here's the code for that (it goes in the include):

Hope this helps someone. It took me a little bit of tinkering to get it just right.

Thanks,
I will update the next version with those improvements.

Billspaintball 04-27-2008 05:40 AM

Quote:

Originally Posted by Triky (Post 1482762)
I can't get it work.

See item 1 in the troubleshooting guide.
https://vborg.vbsupport.ru/showpost....23&postcount=2

Ryan Ashbrook 04-30-2008 04:51 AM

I got file based avatars to work.

In the login_inc.php file find:

PHP Code:

$file $forumpath "image.php?u=$userid"

And replace it with:

PHP Code:

    if ( $vbulletin->options['usefileavatar'] == )
    {
        if ( 
$vbulletin->userinfo['avatarid'] == )
        {
            
$file $forumpath $vbulletin->options['avatarurl'] . "/avatar" $userid "_" $vbulletin->userinfo['avatarrevision'] . ".gif";
        }
        else
        {
             
// Unfortunately, need to query the database for the avatar, will work on array caching all avatars later.
             
$query $db->query_first "SELECT * FROM " TABLE_PREFIX "avatar WHERE avatarid = " $vbulletin->userinfo['avatarid'] . " ; " );
             
$avatar $db->fetch_array $query );
            
$file $forumpath $avatar['avatarpath'];
        }
    }
    else
    {
        
$file $forumpath "image.php?u=" $userid;
    } 

Individual users may need to tweak the avatar paths based on their settings, however this will probably work for most.

Ryan Ashbrook 04-30-2008 04:55 AM

Quote:

Originally Posted by davide101 (Post 1487778)
Does anyone know how to access the profile url? It's not located in $vbulletin->userinfo and I'm sure where else to look. I'd like to link the avatar there.

Use this:

PHP Code:

echo ( "<a href=\"" $forumpath "member.php?u=" $vbulletin->userinfo['userid'] . "\">avatar image code here</a>" ); 


Javi_gray 04-30-2008 05:22 AM

What would I do if I wanted it to show friend requests in addition to private messaging?

Ryan Ashbrook 04-30-2008 05:54 AM

Quote:

Originally Posted by Javi_gray (Post 1503016)
What would I do if I wanted it to show friend requests in addition to private messaging?

Add this:

PHP Code:

echo ( "You currently have <a href=\"" $forumpath "profile.php?do=buddylist\">" vb_number_format $vbulletin->userinfo['friendreqcount'] ) . "</a> friendship requests." ); 


Javi_gray 05-01-2008 01:58 AM

Quote:

Originally Posted by Ryan Ashbrook (Post 1503035)
Add this:

PHP Code:

echo ( "You currently have <a href=\"" $forumpath "profile.php?do=buddylist\">" vb_number_format $vbulletin->userinfo['friendreqcount'] ) . "</a> friendship requests." ); 


where do you find those phrases? are they located in one of the templates?

Ryan Ashbrook 05-01-2008 03:13 AM

No, none of the code I have posted so far is contained in any templates, only in the file called login_inc.php the mod author provided. (The file you use for the main site)

Javi_gray 05-01-2008 03:30 AM

Oh ok. Is there anyway to get all the notifications to show up. Like the ones that come from the dropdown menu.

croft 05-02-2008 12:33 PM

How can i fix it so when you are logged in it looks like on the forum ? 'Laying down not standing up' ?

And thanks for this :)

Ryan Ashbrook 05-02-2008 11:59 PM

Quote:

Originally Posted by Javi_gray (Post 1504127)
Oh ok. Is there anyway to get all the notifications to show up. Like the ones that come from the dropdown menu.

Sorry, I don't know, time doesn't permit me to dive into the workings of the notifications menu yet.

Quote:

Originally Posted by croft (Post 1505705)
How can i fix it so when you are logged in it looks like on the forum ? 'Laying down not standing up' ?

And thanks for this :)

If you mean the table, then that all depends on your website's design. You should be able to reference vBulletin's own navbar for examples, shouldn't be too hard.

croft 05-08-2008 11:48 AM

Quote:

Originally Posted by Ryan Ashbrook (Post 1506271)
Sorry, I don't know, time doesn't permit me to dive into the workings of the notifications menu yet.



If you mean the table, then that all depends on your website's design. You should be able to reference vBulletin's own navbar for examples, shouldn't be too hard.

Actually its not that easy, not for me anyway. My navbar template looks nothing like this php file in way o layout or coding :( Im not a coder guy and could use some help with this if possible ?

ramsayeg 05-08-2008 07:51 PM

I included global.php and I suddenly had an error with CuteNews:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/content/xxx/html/xxx/private/v3beta/newsconf/inc/functions.inc.php on line 43

The news showed, but this error came up at the top of the page. Is anyone aware of anything?

Update: Well, looks like I have ANOTHER problem and this is about the cookies it seems, as it logs me in but doesn't show. I have using different domains for the site/forums, will it cause me problems to log in in the forums, if I enter a custom Cookie Domain of my website's domain?

ramsayeg 05-09-2008 06:11 PM

Sorry to bump but, can anyone help me? (read previous post)

steveheinsch 05-12-2008 07:23 PM

How does this work with vb 3.7 GOLD? I assume fine, but just wanted to check.

Ryan Ashbrook 05-13-2008 02:02 AM

Quote:

Originally Posted by croft (Post 1512595)
Actually its not that easy, not for me anyway. My navbar template looks nothing like this php file in way o layout or coding :( Im not a coder guy and could use some help with this if possible ?

I'm not great with HTML, sorry.

Quote:

Originally Posted by ramsayeg (Post 1513021)
I included global.php and I suddenly had an error with CuteNews:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/content/xxx/html/xxx/private/v3beta/newsconf/inc/functions.inc.php on line 43

The news showed, but this error came up at the top of the page. Is anyone aware of anything?

Unsure, I don't remember htmlspecialchars() being used in it, unfortunately I don't have time to test.

Quote:

Update: Well, looks like I have ANOTHER problem and this is about the cookies it seems, as it logs me in but doesn't show. I have using different domains for the site/forums, will it cause me problems to log in in the forums, if I enter a custom Cookie Domain of my website's domain?
I'm unsure of this as well, Cookies are not my area of expertise.

Quote:

Originally Posted by steveheinsch (Post 1517562)
How does this work with vb 3.7 GOLD? I assume fine, but just wanted to check.

Works perfect, I'm using it right now. :)


All times are GMT. The time now is 05:03 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.01544 seconds
  • Memory Usage 1,915KB
  • 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_code_printable
  • (21)bbcode_php_printable
  • (21)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete