vb.org Archive

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

Billspaintball 02-14-2006 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 look here.

This uses the vB 3.5 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 is a work in progress and currently a beta version. It was a little rushed as a few people were pushing for it ;) Its missing a couple of planned things like newest member etc, but they will be added in a later version.

This script has been confirmed as working on
  • vB 3.5.x - All Versions
  • vB 3.6.x - All Versions

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

Changelog

Version 2.20 (24th April 2007)
  • Fixed - // in paths bug
  • Fixed - Javascript warning in some browsers
  • Fixed - Tidied up some code
  • Fixed - Avatar display code bug

Version 2.10 (4th June 2006)
  • Fixed - "MySQL Error : Invalid SQL " when using Database thread/forum marking.
  • Fixed - Javascrip error in some versions of IE.

Version 2.00 (16th April 2006)
  • Fixed - "MySQL Error : Unknown column 'newposts' in 'field list' "
  • Fixed - Number of PM's not displaying in all installs.
  • Added - Displays date and time of last login.
  • Added - Total number of saved PM's.
To upgrade just overwrite the existing login_inc.php file with the new one.
You will need to re-edit the path on line 3 and also redo any formatting changes you may have done for the last version.

Version 1.0 (15th Feb 2006)
  • Initial Release


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 02-15-2006 10:32 AM

Edit: This usage and trouble shooting guide has been updated as of 24th of April 2007


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.

Snake 02-15-2006 11:12 AM

Awesome! Just awesome! :)

AraServ 02-15-2006 11:52 AM

Goood :)

chimaira 02-15-2006 12:51 PM

Hah amazing.. Going to try it now

Hornstar 02-18-2006 08:31 AM

does it have to be on the same server or can you make it read off the database from another site?

Billspaintball 02-19-2006 11:00 AM

Quote:

Originally Posted by hornstar1337
does it have to be on the same server or can you make it read off the database from another site?

Needs to be on same domain.

White_Snake 02-19-2006 09:00 PM

i got this error when i run the script:
[sql]
Database error in vBulletin 3.5.3:

Invalid SQL:
UPDATE session SET newposts = '' WHERE userid = '1';

MySQL Error : Unknown column 'newposts' in 'field list'
Error Number : 1054
Date : Sunday, February 19th 2006 @ 06:56:38 PM
[/sql]

maybe a bug

kr580 02-19-2006 10:43 PM

Quote:

Originally Posted by White_Snake
i got this error when i run the script:
[sql]
Database error in vBulletin 3.5.3:

Invalid SQL:
UPDATE session SET newposts = '' WHERE userid = '1';

MySQL Error : Unknown column 'newposts' in 'field list'
Error Number : 1054
Date : Sunday, February 19th 2006 @ 06:56:38 PM
[/sql]

maybe a bug

I get the same exact message. Any ideas?

nicedreams 02-20-2006 03:45 PM

Quote:

Originally Posted by kr580
I get the same exact message. Any ideas?

There is no newposts field in the session table.

Jim

Billspaintball 02-20-2006 09:51 PM

Quote:

Originally Posted by nicedreams
There is no newposts field in the session table.

Jim

Just realised I based part of this on a modified table structure.
Will fix in the next day or two.

Billspaintball 02-21-2006 06:15 AM

Ok, I think I have a fix for the problem.
Unfortunantly, I dont have access to an unmodified vB database to test it on.

If anyone who has had the problem wants to try the fix, its available here.
http://www.cwp.id.au/login_inc.zip
Please let me know if it fixes the problem, so I can modify the file here appropriatly.

dkleehammer 02-24-2006 04:32 AM

I'm getting this error wether I'm logged into the forums already or not:
Fatal error: Call to a member function query_read() on a non-object in /var/www/html/forums/includes/login_inc.php on line 139

This is all running on localhost. Am I missing something?

Billspaintball 02-24-2006 04:43 AM

did you use the revised test one in this post
https://vborg.vbsupport.ru/showpost....6&postcount=12
or the one on the 1st post?

dkleehammer 02-24-2006 03:16 PM

I used the revised version. For some reason the db is not being set as an object. Is there something that I need to do besides editing one line and including this file in the main page?

erinys 03-02-2006 02:58 PM

Is this mod functioning good at the moment? would love to implement this at my site ;)

ROTPAR 03-02-2006 04:13 PM

Works good but I have a problem with the avatar resize option.

Warning: getimagesize(http://www.xxxmypage.com/upload/image.php?u=1) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /home/xxx/public_html/login_inc.php on line 27

Thanks for help

erinys 03-02-2006 07:14 PM

Ive tried installing.. but the moment i put this code in the template of my site

<?php
chdir('/home/6304/bunnybunch.nl/HTML/community');
require_once('/home/6304/bunnybunch.nl/HTML/community/global.php');
?>

im getting errors

erinys 03-02-2006 07:15 PM

this is the error

Warning: main(administrator/components/com_smf/config.smf.php): failed to open stream: No such file or directory in /home/6304/bunnybunch.nl/HTML/templates/247portal-b-grey/index.php on line 33

Fatal error: main(): Failed opening required 'administrator/components/com_smf/config.smf.php' (include_path='.:/usr/local/lib/php') in /home/6304/bunnybunch.nl/HTML/templates/247portal-b-grey/index.php on line 33

erinys 03-03-2006 06:31 AM

Ok little update ;)

I have now been able to succesfully get this working... but.. only on the complete bottom of my site lmao :)

is there somethign i can change on this code to work with my site template?

<?php
chdir('/home/6304/bunnybunch.nl/HTML/community');
require_once('/home/6304/bunnybunch.nl/HTML/community/global.php');
?>
<?php
require_once('/home/6304/bunnybunch.nl/HTML/community/login_inc.php');
?>

if i post the above code "anywhere" in my template where it is followed by a include_once (and my site has many of those) for some reason, nothing is included/found :)

anyway, thanks for the help!

Billspaintball 03-03-2006 11:06 AM

Quote:

Originally Posted by dkleehammer
I used the revised version. For some reason the db is not being set as an object.

Can you explain a little more please?

Billspaintball 03-03-2006 11:13 AM

Quote:

Originally Posted by ROTPAR
Works good but I have a problem with the avatar resize option.

Warning: getimagesize(http://www.xxxmypage.com/upload/image.php?u=1) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /home/xxx/public_html/login_inc.php on line 27

Thanks for help

Is your forums base directory /upload/ ?
Do you use the verification images for registration?

Billspaintball 03-03-2006 11:17 AM

Quote:

Originally Posted by erinys
Ok little update ;)

I have now been able to succesfully get this working... but.. only on the complete bottom of my site lmao :)

is there somethign i can change on this code to work with my site template?

<?php
chdir('/home/6304/bunnybunch.nl/HTML/community');
require_once('/home/6304/bunnybunch.nl/HTML/community/global.php');
?>
<?php
require_once('/home/6304/bunnybunch.nl/HTML/community/login_inc.php');
?>

if i post the above code "anywhere" in my template where it is followed by a include_once (and my site has many of those) for some reason, nothing is included/found :)

anyway, thanks for the help!

In that case somthing is conflicting.
Do you run any other vB scripts on that page?

ROTPAR 03-03-2006 12:13 PM

Quote:

Originally Posted by Billspaintball
Is your forums base directory /upload/ ?
Do you use the verification images for registration?

That?s right, the base directory is /upload/
I use GD in the vbulletin options if this is what you mean..I don?t use Image Verification for the new user register process.
What could be the problem ?

Greets and THX for help

erinys 03-03-2006 12:39 PM

@bill

no not any VB scripts.. but it seems to be conflicting with whatever include_once is right below it..

im pasting it in a template btw.. wich also has codes for SMF forums, discussbots etc etc (im upgrading from SMF to VB atm)

idwf 03-03-2006 04:04 PM

I've got this to work....so don worry about supporting the other one. However.

one little bug, if you have no new PM's you get

Quote:

You have new message(s) since your last visit.
------------

I've done a lot of bug checking and it turns out that it wasn't your scripts causing me errors. i apolagise :) :cheeky:

erinys 03-04-2006 01:30 PM

Ive got it working now.. cause i switched forums today i was able to remove a lot of include_once tags, and now it works :)

bug: the link to new PM's is actually a link to the last new posts.. and there are missing a lot of <br> etc to make it look nice :)

so i editted it a bit

thanks for this Mod!

idwf 03-04-2006 05:18 PM

Quote:

Originally Posted by erinys
Ive got it working now.. cause i switched forums today i was able to remove a lot of include_once tags, and now it works :)

bug: the link to new PM's is actually a link to the last new posts.. and there are missing a lot of <br> etc to make it look nice :)

so i editted it a bit

thanks for this Mod!

yeah, i've edited the design with some <br>'s aswell. I cant wait till all the features are installed... :)

Kirk Y 03-05-2006 07:56 PM

I've got a bit of a problem. Whenever a User changes their avatar, the avatar shown on login_inc is the one they had before they changed.

rolliet 03-06-2006 02:22 AM

I have what is probably an easy question. How do I add more then 1 usergroup to the code?

if ($vbulletin->userinfo['usergroupid'] == '25' )

I have tried different things and still can only allow 1 usergroup to access the page.

Thanks

erinys 03-06-2006 06:34 AM

acidburn:

CTRL-F5,. its normal that your browser cashes the image!

Billspaintball 03-06-2006 08:52 AM

Quote:

Originally Posted by idwf

one little bug, if you have no new PM's you get



:

Oh ok.
Next release will have 0 if there are none.

Billspaintball 03-06-2006 08:55 AM

Quote:

Originally Posted by erinys
bug: the link to new PM's is actually a link to the last new posts..

Sorry, will fix in next release (sometime this week).

Quote:

and there are missing a lot of <br> etc to make it look nice :)
Yeah, I only have the basics in there.
I left stying out because it makes it look too complicated to some people, while most want to style it to suit their site anyhow.
Quote:

thanks for this Mod!
Your welcome :)

Billspaintball 03-06-2006 08:57 AM

Quote:

Originally Posted by acidburn0520
I've got a bit of a problem. Whenever a User changes their avatar, the avatar shown on login_inc is the one they had before they changed.

Im pretty sure that is just your browser caching the old picture.
Just force a browser refresh to fix.

CTRL + F5 (I think)

Billspaintball 03-06-2006 09:11 AM

Quote:

Originally Posted by rolliet
I have what is probably an easy question. How do I add more then 1 usergroup to the code?

if ($vbulletin->userinfo['usergroupid'] == '25' )

I have tried different things and still can only allow 1 usergroup to access the page.

Thanks

Its late and I havent tested this yet but try something like
PHP Code:

if ($vbulletin->userinfo['usergroupid'] == '25' 
     
or $vbulletin->userinfo['usergroupid'] == '26' 
     
or $vbulletin->userinfo['usergroupid'] == '27'



ROTPAR 03-06-2006 09:29 AM

Hi,

can anyone help me with my problem please ? I have no idea what to do....see my last posting.

Thanks a lot

Billspaintball 03-06-2006 09:44 AM

Quote:

Originally Posted by ROTPAR
Hi,

can anyone help me with my problem please ? I have no idea what to do....see my last posting.

Thanks a lot

I assume you mean this ?
PHP Code:

Warninggetimagesize(http://www.xxxmypage.com/upload/image.php?u=1) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /home/xxx/public_html/login_inc.php on line 27 

Since the path looks correct, and the error refers to function.getimagesize I would suspect that its probably a webserver configuation issue.

You can just commentout the lines to do with resizing the image and it will still display the avatar, but at the origional size.

rolliet 03-06-2006 08:49 PM

Quote:

Originally Posted by Billspaintball
Its late and I havent tested this yet but try something like
PHP Code:

if ($vbulletin->userinfo['usergroupid'] == '25' 
     
or $vbulletin->userinfo['usergroupid'] == '26' 
     
or $vbulletin->userinfo['usergroupid'] == '27'



Thats what I needed, worked great. Thanks for the help. :up:

idwf 03-07-2006 04:02 PM

Quote:

Originally Posted by acidburn0520
I've got a bit of a problem. Whenever a User changes their avatar, the avatar shown on login_inc is the one they had before they changed.

aah. iom getting this too :):tired:

johnn 03-23-2006 03:39 AM

Anything on the PM issue? I get nothing when I get a new PM. I see it on my board, but not on my site's index page.


All times are GMT. The time now is 05:22 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.01660 seconds
  • Memory Usage 1,889KB
  • 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
  • (4)bbcode_code_printable
  • (12)bbcode_php_printable
  • (19)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)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