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 - Simple vB User login and access control on non vB pages (https://vborg.vbsupport.ru/showthread.php?t=173693)

Billspaintball 03-20-2008 10:00 PM

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

This is a cut down version of the user authentication and access control system I use on the non vB pages on my website.

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 displaying to non members only, and/or let members access to specific content.

Ive cut it down to the bare minimum that it needs to work, no fancy stuff such as avatars, PM's, or even formating.

I will try and offer support, but work and family commitments mean I don't 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


Change log

Version 2.00 (21st March 2008)
  • Initial vB 3.7.x 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 03-21-2008 11:02 AM

Usage

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

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"; }
    
?>

You can of course use multiple usergroups by just modifiying the if statement a little.
For example:
PHP Code:

if ($vbulletin->userinfo['usergroupid'] == '9'  
     
or $vbulletin->userinfo['usergroupid'] == '6'  



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.

punchbowl 03-21-2008 11:07 AM

superb stuff, brilliantly presented info. Thanks

NeuroLancer 03-21-2008 11:12 AM

Good one :up:

I have been wanting to do this but have been putting it off due to time restrictions.

You've made things alot easier and quicker for me by creating this mod, thank you so much.

*installed

dilbert 03-22-2008 02:15 AM

Wow, very timely!
I am developing a new section of the site, but it will be for forum users only.
My one glitch, the pages will be in cold fusion, not php. Any chance something like this could be modified for cfm pages?

ramsayeg 03-22-2008 02:37 AM

Just about to launch my new layout and wanted something like this to be released, thanks!

smooth-c 03-29-2008 04:19 PM

wow! this is great!!

Billspaintball 04-27-2008 05:42 AM

Quote:

Originally Posted by dilbert (Post 1471253)
Wow, very timely!
I am developing a new section of the site, but it will be for forum users only.
My one glitch, the pages will be in cold fusion, not php. Any chance something like this could be modified for cfm pages?

I have zero experience in cold fusion so I cant answer this either way.

texas_txu 05-13-2008 04:13 AM

I have been struggling getting this to work for me. I am just trying to get the test.php script to work first. when i am not logged in, i cannot log into the pages off of vb, they are linked to the folder i have my non-vb files in, rather than the forum folders.
www.mydomain.com/forums
www.mydomain.com/music

i want to use this script in the music folder. when i try to load the test.php file, it looks for images and registration stuff under /music/images and /music/register.php rather thant /forums/images and what not. i have tried various setups for the login_inc.php file and also put the music folder inside the /forums dirstory (/forums/music) and still with no luck.

im pretty sure its something stupid and i'm over thinking this whole problem. but your help would be much abliged. thanks much.

pdblizzard 05-13-2008 10:52 AM

I had a devil of a time with this too, until I changed the URL in my login_inc.php from
this:

PHP Code:

$forumpath "http://www.yoursite.com/forums/"

to this:
PHP Code:

$forumpath "./forums/"

I have no idea if this will help you in your circumstances, but I thought I would share it just in case. I had multiple domain names pointing to the same content.

texas_txu 05-14-2008 06:23 AM

still running into issues...the login page that is generated makes links for the registration page and the login script to the /music/log.php etc...rather than /forums/login.php. even the logo is messed up

justchil 05-15-2008 06:36 PM

Super simple and works great!

pdblizzard 05-15-2008 06:52 PM

Quote:

Originally Posted by texas_txu (Post 1519087)
still running into issues...the login page that is generated makes links for the registration page and the login script to the /music/log.php etc...rather than /forums/login.php. even the logo is messed up

Maybe if you post more information, i.e., the php code with your path statements (the part you're supposed to customize) we can help you out.

texas_txu 05-16-2008 07:07 AM

Quote:

Originally Posted by longin_inc.php
<?php
// Version 2.00
// Released March 21st, 2008
// For vB 3.7.x
// Edit the line below to show path to your forums
$forumpath = "./forums/";

also tried with
$forumpath = "https://www.mydomain.com/forums/"; (yes secure domain)
$forumpath = "c:\domains\mydomain\wwwroot\forums"; (IIS Server nomenclature)

and my php test file looks like (in mydomain.com/forums/music with login_inc in mydomain.com/:
Quote:

<?php
$curdir = getcwd ();
chdir('../forums');
require_once('../forums/global.php');
echo getcwd();
chdir ($curdir);
echo getcwd();
?>

....

<?php
echo getcwd();
require_once('../login_inc.php');
?>

berry05 05-18-2008 01:08 PM

i did this hack and got this error...

Unable to add cookies, header already sent.
File: /home/content/b/e/r/berry05/html/tyler.php
Line: 3

and i did what the troubleshooting told me to do also...

oz_girl 05-31-2008 11:59 PM

This si another awesome mod, will it be to hard for a newbie to use?

fsbmax 08-03-2008 09:04 PM

i keep getting errors :s

Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/fragreel/public_html/td2142/template/header.inc.php on line 4

Warning: require_once(/home/fragreel/td2142/forum/global.php) [function.require-once]: failed to open stream: No such file or directory in /home/fragreel/public_html/td2142/template/header.inc.php on line 5

Fatal error: require_once() [function.require]: Failed opening required '/home/fragreel/td2142/forum/global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/fragreel/public_html/td2142/template/header.inc.php on line 5

Hereward 08-04-2008 06:31 AM

I wonder if its possible to see a working example rather than just the code snippets?

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";
    }
?>

I am looking to create a page (within a separate CMS) which checks to see if the current user is authenticated against the forum. This code above looks promising but it seems incomplete.

I am wondering, where is the variable $vbulletin created? Does it need to be declared as a global?

cheers (:

ramsayeg 08-06-2008 11:22 PM

have some problems with this, the form works OK but when it returns to the page it still doesn't show me as logged on...

I did everything in the instructions... anyone cares to help?

ramsayeg 08-07-2008 07:34 AM

anyone?

I even managed to lock myself out by changing the cookie domain etc. and then had to reverse it by using tools.php. I'd love some ideas....

ForgotenDynasty 08-08-2008 03:14 PM

When i inserted it in to my blog so my users can login in my word press bridge i found my self doing alot of /" because often you would use quotes to open the echo then you would use them again in the html

and it also seems that it doesn't pick up when the user is logged in. it just brings the form back

TheInsaneManiac 08-08-2008 06:13 PM

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/XXXXX/public_html/news/inc/functions.inc.php on line 43

Seems to be affecting cutenews.

PaylaX 09-21-2008 03:46 PM

Appears to login ok but won't show I as logged in,

In Simple Login Instructions;
Quote:

AdminCP -> vBulletin Options -> Cookies and HTTP Header Options -> Path to Save Cookies
change 'Suggested Settings' dropdown from '/forums/' to '/' or 'yourdomain.com'
I did, but won't show I as logged in again again..

qbn720 10-01-2008 07:30 AM

Quote:

Originally Posted by PaylaX (Post 1627045)
Appears to login ok but won't show I as logged in,

In Simple Login Instructions;
I did, but won't show I as logged in again again..

I'm having the same problem, I even added the urls on the whitelist. I'm not sure what I'm doing in correct but here's my entire file, thus far I've only been testing. However, my issue pertains to the fact that I'm actually using two subdomains. My forums has a subdomain and the other aspect of the site that I'm using also has a subdomain.

How do I get around this?

Shamil. 10-13-2008 06:35 PM

Anyone?

qbn720 11-02-2008 10:37 PM

<font face="Tahoma">I found out that you have to reset your browsers then use the website, or else it will continue cause problems.</font>

Jeffonfire 11-23-2008 05:54 PM

I've got the same problem as some others, the form seems to work, but it still shows as logged off.

I've tried to set the path of the cookies to "/" and then clear my cookies then try to connect and still doesn't work.

I found out that if I go directly to the forum then connect then move to another section of my website, it'll then show as if I'm logged.

Thanks for help

Triky 11-30-2008 07:37 PM

Quote:

Ive cut it down to the bare minimum that it needs to work, no fancy stuff such as avatars, PM's, or even formating.
So.. can you please post also an extended version? :)

lifanovsky 12-08-2008 06:47 PM

I have even installed additional hack to use cookie on few different domain. But still this plugin shows that I am not logged in... Will there be instructions or updated version?

gct13 12-12-2008 04:18 PM

Great hack.

I was wondering if there was a way to suppress the banned notification for banned users? If a banned user browses non-vb pages, those pages are also blocked from view. I'd prefer that non-vb pages with this hack are viewable for banned users.

Submerge 12-12-2008 04:48 PM

Thank you!

MadsK 12-19-2008 08:39 AM

I've finally got the script working - almost.

I can log in alright - but it does not show that i am logged in on the frontpage - only the log in box.

I've checke my cookies path in the admincp and it is set to "/" - I've tried different browser and clearing my cookies etc. But nothing seems to work?

If it is to any help - im using wordpress.

Jeffonfire 12-20-2008 09:41 PM

In response of MadsK, this bug seems to happen to a lot of us. I would really like to get some help from the developer of the code or from anyone else to find a way to solve this problem. This login box is a really important part of my website and right now it's a pain in the a** not to be able tu use it

MadsK 12-22-2008 10:26 PM

I found the trick to make it happen.

Below is the code i use for my site. It has been altered a little with some extra links after you've logged in but they can be changed. I've tested it with a couple of different friends on different computers, operating systems and browsers and it works on all of them.

With that said this is only working with Wordpress as it collects the cookie from the wordpress database and outputs it. When logging out it also clears both wordpress and vbulletin cookie!

I would really like some feedback on it :)

You can see it in action on my website http://www.swtorcommunity.com

Code:

<?php
// Version 2.00
// Released March 21st, 2008
// For vB 3.7.x
// Edit the line below to show path to your forums
$forumpath = "/forum/";


// You dont have to edit anything underneath here,
// but you can if you wish to style the login box
// to match the style of your site.

// ---------------
// COPYRIGHT STUFF
// ---------------
// You are free to use and modify this script in anyway you like.
// However,
// - Do not remove copyright notice
// - Dont pass it off as your own work.
//
// This script is provided free of charges, however If you use this on a commercial
// venture a small paypal donation to cwp@cwp.id.au would be apprecieated.


// We check if user is logged in
                if (isset($user_ID)) {
                        // User is logged in
                        echo "<div id=loginwelcome>";
                        $user_info = get_userdata($user_ID);
                        echo $before_widget . $before_title . __("Welcome "). $user_info->display_name . $after_title;
                        echo "</div>";
// If logged in display logout link
echo "<br />";

echo "<div id=loginmeta>";

echo "<a href=\"".$forumpath."usercp.php";
echo "\">";
echo "User CP</a>";

echo "<a href=\"".$forumpath."private.php";
echo "\">";
echo "Private Messages</a>";

echo "<a href=\"".$forumpath."search.php";
echo "\">";
echo "Search</a>";

echo "<a href=\"/wp-login.php?action=logout\">Logout</a>";

echo "</div>";

} else { // If user is not logged in, we do this stuff

// Display login boxes + button
// You can style this with html or CSS as normal if desired.
echo"
        <form id=loginform action=\"".$forumpath."login.php\" method=post onsubmit=md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf)>
        <script type=text/javascript src=\"".$forumpath."clientscript/vbulletin_md5.js\"></script>
       
        <input name=vb_login_username value=Username id=user onFocus=this.value='' type=text id=navbar_username size=10 />
                       
        <input name=vb_login_password type=password id=password size=10 value=Password onFocus=this.value='' />
        <br />
               
        <label id=rememberme for=cb_cookieuser_navbar>Remember Me?<input name=cookieuser type=checkbox id=cb_cookieuser_navbar value=1 checked=checked />
        </label>
       
               
        <input type=submit id=submit value=Login title=$vbphrase[enter_username_to_login_or_register] value=\"Log In\" />
               
        <input type=hidden name=s value=$session[sessionhash] />
        <input type=hidden name=do value=login />               
        <input type=hidden name=vb_login_md5password />
        <input type=hidden name=vb_login_md5password_utf />

        </form>
";

}
?>


tirol07 12-26-2008 12:38 AM

Than you for this useful hack!

How can i include header and navbar template to this script?

Jeffonfire 12-26-2008 06:02 PM

MadsK, any way to make your code work for those who aren't on Wordpress?

MadsK 01-03-2009 08:14 PM

You could try to replace the $user_id with the vbulletin equilant. But i'm not sure which that is.

daggz 01-08-2009 04:00 AM

Okay - first off Props to the poster - this is a great little addon

Now if anyone is having issues with login.php here is the be all fix

put the .php file inside your /forums directory

this will solve most issues as you are using vbulletin functionality from outside it's operating path - and is where you are most likely running into issues

For example prior I had a php page at mydomain/LINKS - the index.php was the link checker. When adding this hack in that /LINKS dir I was having issue (and I am not a code noob) - however the moment I put the php in my /forums directory and replaced my index.php on /LINKS with a frame loading the php from it's new location - everything works fine

Any just a bitta info - oh and always - perfect syntax people

Peace

.*

Jeffonfire 01-09-2009 02:11 AM

Nope it doesn't work.

I put the .php that contains the login form in my forum folder, still shows as if i'm logged out.

cowmoo 02-20-2009 03:15 AM

Ok, I've been trying to get this working for a fair while now, I'm getting the same problem as a lot of people here, the script continues to show the login form after logging in.

I'm running Ubuntu and FF3, it shows logged out, however running under IE6 (using wine) it worked correctly the first time only (would work again even clearing cookies, history, re-opening browser etc).
I noticed when it did work it sent back a session string as a _GET variable, but I couldn't get it to do that more than once without resetting my cookies etc.

Still gonna work on it some more, but thought I'd share what I've found so far.

cOwMoO


All times are GMT. The time now is 06:05 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.02841 seconds
  • Memory Usage 1,886KB
  • 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
  • (5)bbcode_code_printable
  • (13)bbcode_php_printable
  • (7)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