vb.org Archive

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

Billspaintball 12-01-2006 10:00 PM

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

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

This uses the vB 3.6 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.

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 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.6
  • vB 3.6.1
  • vB 3.6.2
  • vB 3.6.3
  • vB 3.6.4
  • vB 3.6.5


Changelog

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

Version 1.0 (2nd December 2006)
  • Very similar to my vB 3.5 version, however logout bug fixed and should be more compatible with other scripts on your page.



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 12-02-2006 02:56 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.

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.

thepub 12-02-2006 02:58 AM

thanks!

projectego 12-02-2006 08:35 AM

Great work. Thanks!

JamieLee2k 12-02-2006 11:21 AM

Any chance of seeing a demo of some kind, I am wanting a login page for my homepage in which users can see there info on the homepage like PM's new posts, etc....

Billspaintball 12-02-2006 12:01 PM

Quote:

Originally Posted by JamieLee2k (Post 1129952)
I am wanting a login page for my homepage in which users can see there info on the homepage like PM's new posts, etc....

Use my 3.5 hack - (also works fine on 3.6) for that
See my sig for link to it.

JamieLee2k 12-02-2006 01:08 PM

But if I am using 3.6 why do I need to use 3.5 if the hack is pretty much the same, if not the same?

Also I want the hack for HTML pages, if thats possible

Billspaintball 12-02-2006 09:43 PM

Quote:

Originally Posted by JamieLee2k (Post 1129990)
But if I am using 3.6 why do I need to use 3.5 if the hack is pretty much the same, if not the same?p

The 3.5 deluxe version https://vborg.vbsupport.ru/showthread.php?t=108026 has the extra stuff that you wanted like PM's
It also works fine with all versions of vB 3.6

Quote:

Also I want the hack for HTML pages, if thats possible
No. It only works on PHP pages.

Gastongr 12-03-2006 03:01 AM

Awesome work!, thanks so much.

mathias 12-03-2006 08:46 AM

i've got it working, but only when i remove my other script that i have to call which is require_once('./vBExternal.php'); for another add-on....how do i stop the top part of the login code

Code:

<?php
chdir('/path/to/your/forums');
require_once('/path/to/your/forums/global.php');
?>

from conflicting with the vBExternal? i found this is the only way i can do it.... otherwise the main page doesn't remember the user if i put the full url to the .php that includes the login page code with the

Code:

<?php
chdir('/path/to/your/forums');
require_once('/path/to/your/forums/global.php');
?>


Billspaintball 12-04-2006 01:06 AM

Quote:

Originally Posted by mathias (Post 1130608)
from conflicting with the vBExternal? i found this is the only way i can do it

Yes there is a conflict between this and vB external.
We tried to track it down with an earlier release of this but with no luck.

A workaround others have used is use vBexternal for the front page and this hack on the rest to provide access control.

mathias 12-04-2006 06:30 AM

Quote:

Originally Posted by Billspaintball (Post 1131318)
Yes there is a conflict between this and vB external.
We tried to track it down with an earlier release of this but with no luck.

A workaround others have used is use vBexternal for the front page and this hack on the rest to provide access control.


np, thanks for that :D

unit3029 12-04-2006 09:58 PM

Just what the docotor ordered :) Great hack

Thanks

Osterling 12-05-2006 01:44 AM

It works great! I have one question however, how can I display the username?

Billspaintball 12-05-2006 01:54 AM

Quote:

Originally Posted by Osterling (Post 1132134)
It works great! I have one question however, how can I display the username?

To display the username just put
PHP Code:

echo $vbulletin->userinfo['username']; 

in the page where you want it.

Osterling 12-05-2006 11:55 PM

I am trying to put $vbulletin->userinfo['username'] into a variable named $username, however it isn't working. Here is my code, is there something I am missing?

$username = $vbulletin->userinfo['username'];

eob 12-06-2006 09:50 PM

I'm having an interesting problem...

If I run this hack, it deletes any variable called before it, for example, if id=6 before global.php, id = NULL afterwards?

Otherwise a great hack, but mucho help would be appreciated?

Billspaintball 12-07-2006 03:43 AM

Quote:

Originally Posted by Osterling (Post 1132875)
I am trying to put $vbulletin->userinfo['username'] into a variable named $username, however it isn't working. Here is my code, is there something I am missing?

$username = $vbulletin->userinfo['username'];


That should work as long as the page with that code includes global.php

You dont have anything else that uses the variable $username do you?
What happens if you name the variable something else like $member_name ?

svoec 12-07-2006 03:57 AM

I have one strange issue, when someone is logged out, and they log in (or if they click the log out link) -- it opens in a new window --
is that normal behavior ?

the plan I had for this makes it a look a bit strange...
thanks for the help

SunderlandJ 12-07-2006 09:36 AM

I need help....

please check http://gunge.gothic-craving.com/links.php for a demo

I had to remove chdir line as it wasnt finding a file, which kept causing errors, now when I use the login box, it logs me in, but the login box stays there and at the bottom of the screen it says "done, with errors on page"

I know nothing about php so I would appreciate some help here. I have no idea what im doing or anything :(

Leigh

eob 12-07-2006 11:17 AM

Hey Bill, any chance of helping me out with my id=6 problem? It's for a giant of a site, would love to get it working as I've styled it in beautifully and everything :)

tobybird 12-10-2006 06:16 PM

Great hack! Thanks so much! I really needed this. :)

Installed!

ManagerJosh 12-13-2006 06:06 AM

Hey Bill:

Out of curosity, does this support multiple unique domains and subdomains,?

Ie. vBulletin is here: http://www.myvbinstall.com
But login pages are at http://beta.mydomain1.com
http://placeholder.domainworld2.com

?

Doctor Who 12-13-2006 10:46 PM

Any idea what would be causing the attached error, and how to fix it? The only javascript that is included in the page is from the login_inc.php file.

Aur-Phala.Com 12-14-2006 05:47 PM

hey any idea how i could make it show on whosonline page
so people who are using my page www.aur-phala.com/hotmail
will show up on whos online so i can see whos checking that page out

Billspaintball 12-19-2006 03:09 AM

Quote:

Originally Posted by ManagerJosh (Post 1137581)
Hey Bill:

Out of curosity, does this support multiple unique domains and subdomains,?

Ie. vBulletin is here: http://www.myvbinstall.com
But login pages are at http://beta.mydomain1.com
http://placeholder.domainworld2.com

?

Thats very hit and miss Im afraid.
Some have been able to do that, but others havent.

You can try, and there is some information on that in the troubleshooting guide but dont be too disapointed if it wont work. :(

Billspaintball 12-19-2006 03:20 AM

Quote:

Originally Posted by Aur-Phala.Com (Post 1138589)
hey any idea how i could make it show on whosonline page
so people who are using my page www.aur-phala.com/hotmail
will show up on whos online so i can see whos checking that page out

Easy way would be to just make that page in a vB forums page.
Theres a couple of hacks here that do just that.

Aur-Phala.Com 12-22-2006 01:15 AM

could you link me to it
the page is a php page tho,so how wud i go abt this liek what needs to be included

Osterling 01-05-2007 09:37 PM

is there a way i can show on my nonvb homepage who is online?

Billspaintball 01-09-2007 03:05 AM

Quote:

Originally Posted by Osterling (Post 1151604)
is there a way i can show on my nonvb homepage who is online?

Sorry,
This mod does not support that.

RobAC 01-23-2007 10:12 PM

I like the user authentication system that PhotoPost and ReviewPost utilize from Techimo.

I don't care about showing avatars and have no desire to do so. I just want the same functionality as PhotoPost has.

Does this hack do the same thing?

Billspaintball 01-25-2007 03:19 AM

Quote:

Originally Posted by RobAC (Post 1166036)
Does this hack do the same thing?

Sorry, Im not familiar whith how they work.

Jasen Hicks 01-27-2007 04:59 AM

Mine isnt working :(

Code:

<?

$curdir = getcwd ();

chdir("htdocs/vb");

require_once("htdocs/vb/global.php");

chdir ($curdir);

?>
<html>
<head>
<title>TRS Compatability Charts</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p><font size="+2" face="Verdana, Arial, Helvetica, sans-serif">TRS Compatability Chart
  </font></p>
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">This information
  has been gathered from a number of resources including books, websites, and
  personal experiences. This in no way can account for the exact creature that
  you are purchasing and should be used as a reference only. Tidewater Reefers
  Society, its members, and users are not liable for this information. We try
  to ensure all the information is accurate and up to date, however, we make no
claims that it is 100% correct.</font></p>

<?
  require_once("login_inc.php");
?>
<?

If ($vbulletin->userinfo['userid']!=0)
    {   
    echo "<a href=\"compatabilityResults.php\"><font face=\"Verdana, Arial, Helvetica, sans-serif\">View
      Compatability Chart</font></a><br>";
    }
       
        else {
    echo "<p><font size=\"-1\" face=\"Verdana, Arial, Helvetica, sans-serif\">You are required to be logged on prior to viewing the chart. Please login now using your Forum Username and Password:</font></p>";
 
    }
?>
<p><br>
  <br>
  <!-- &lt;&lt;MODERATOR/ADMIN ONLY&gt;&gt;<br>
  <a href="compatabilityInput.php">Add a New Creature</a></font></p>
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">&lt;&lt;MODS/ADMIN
  and ALL OTHERS&gt;&gt;<br>
 
  </font>
  -->

  <!-- Export Entire Compatability Chart to CSV</font></p> -->
</p>
<p>&nbsp;</p>
</body>
</html>


Jasen Hicks 01-27-2007 05:03 AM

OK, even with non-moron-2AM code it still doesnt work:

Code:

<?

$curdir = getcwd ();

chdir('/htdocs/vb');
require_once('/htdocs/vb/global.php');

chdir ($curdir);

?>
<html>
<head>
<title>TRS Compatability Charts</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p><font size="+2" face="Verdana, Arial, Helvetica, sans-serif">TRS Compatability Chart
  </font></p>
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">This information
  has been gathered from a number of resources including books, websites, and
  personal experiences. This in no way can account for the exact creature that
  you are purchasing and should be used as a reference only. Tidewater Reefers
  Society, its members, and users are not liable for this information. We try
  to ensure all the information is accurate and up to date, however, we make no
claims that it is 100% correct.</font></p>

<?
  require_once('login_inc.php');

 if($vbulletin->userinfo['userid']!=0)
    {   
    echo "<a href=\"compatabilityResults.php\"><font face=\"Verdana, Arial, Helvetica, sans-serif\">View Compatability Chart</font></a><br>";
    }
       
        else {
    echo "<p><font size=\"-1\" face=\"Verdana, Arial, Helvetica, sans-serif\">You are required to be logged on prior to viewing the chart. Please login now using your Forum Username and Password:</font></p>";
 
    }
?>
<p><br>
  <br>
  <!-- &lt;&lt;MODERATOR/ADMIN ONLY&gt;&gt;<br>
  <a href="compatabilityInput.php">Add a New Creature</a></font></p>
<p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">&lt;&lt;MODS/ADMIN
  and ALL OTHERS&gt;&gt;<br>
 
  </font>
  -->

  <!-- Export Entire Compatability Chart to CSV</font></p> -->
</p>
<p>&nbsp;</p>
</body>
</html>


Billspaintball 01-30-2007 01:44 AM

What exactly is it doing or not doing?
Any error messages?
A little more info please.

Edit:
Your path statement up the top is wrong.
I suspect that your path statement may not be correct.
Do the 2nd step of the troubleshooting guide (post 2) and see what you get.

Jasen Hicks 01-30-2007 11:16 PM

Thanks, looking back i realized that 2AM coding is a bad idea ;) I feel ashamed now.

idwf 02-09-2007 11:31 PM

I've just come back to using my vb and i was wondering if this still works, if not..can someone link me? thanks

Billspaintball 02-11-2007 09:08 PM

Quote:

Originally Posted by idwf (Post 1178797)
I've just come back to using my vb and i was wondering if this still works, if not..can someone link me? thanks

Yes, still working with all versions of 3.6.x to date.

Mysticales 02-18-2007 02:28 AM

Quote:

Originally Posted by Billspaintball (Post 1131318)
Yes there is a conflict between this and vB external.
We tried to track it down with an earlier release of this but with no luck.

A workaround others have used is use vBexternal for the front page and this hack on the rest to provide access control.

Here you go, took me a hour to solve. ^^
https://vborg.vbsupport.ru/showpost....&postcount=399

Mastar 02-20-2007 02:23 AM

How to get this to work wid vbseo?
Code:

Unable to add cookies, header already sent.
File: /home/XXXXX/public_html/index.php
Line: 1
 

 



Search Engine Optimization by vBSEO 3



All times are GMT. The time now is 04:54 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.01631 seconds
  • Memory Usage 1,880KB
  • 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
  • (9)bbcode_code_printable
  • (11)bbcode_php_printable
  • (13)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