Deluxe vB User login and access control on non vB pages
By [email protected]
Version 3.00 - March 21st, 2008
For vB 3.7.x
This document consists of 3 sections.
Installation, which is installation instructions,
Usage which is basic usage commands,
Troubleshooting which is common problems and their fixes
---------------
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 [email protected] would be apprecieated. :-)
This document consists of 3 sections.
Installation, which is installation instructions,
Usage which is basic usage commands,
Troubleshooting which is common problems and their fixes
------------
NEW INSTALLATION
------------
This Hack consists of 2 parts.
Part 1.
Add the following 4 lines right at the top of every page that you want to have access control on your website.
***It is ESSENTIAL that there is NO spaces or anything else before these lines.***
Note that they must be .php pages, not .html
Note that you will have to modify the path in lines 2 and 3 to suit your site before you upload.
<?php
$curdir = getcwd ();
chdir('/path/to/your/forums');
require_once('/path/to/your/forums/global.php');
chdir ($curdir);
?>
After this you have your
<HTML> and <BODY> tags and the rest of your web page.
Where you want to have your login box place this block of code.
<?php
require_once('/path/to/your/login_inc.php');
?>
Part 2.
You will need to edit the file
login_inc.php
You need to edit line 3
$forumpath = "http://www.yoursite.com/forums/";
Change this address to suit your site.
Upload this file to your website, and ensure that the path you entered in part 1 points to it.
-----------------------
UPGRADE FROM 2.10 to 3.00
-----------------------
There is no need to upgrade from 2.10 to 3.00
There is no functional difference.
-----
USAGE
-----
This hack is lacking 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
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
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
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
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. If you get a message saying headers already sent or cookies already sent, 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
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.
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;
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.
Open your /forum/login.php file and look for this code:
error_reporting(E_ALL & ~E_NOTICE);
Below that add
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 secound Server. Then you must set in the config.php on the second server to use the ip of the server won which the VB-Database is running.
5. 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 thetre is no whitespace before the 1st line)
<?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.