View Full Version : Showing Different Stuff When Logged In Or Not...?
SystemLogic
09-16-2001, 05:03 AM
On the front page of a forum, how can I set something up so that it only shows if you are logged in? For example, a message shows up if you are unregistered or not logged in, and goes away when you are logged in.....what if I wanted something the other way around?
BobbiX
09-16-2001, 08:14 AM
Well, here's how I do that ... I'm pretty sure all PHP freaks will know of a better way, but anyway :
<?
require("./global.php");
if ($bbuserinfo['userid']!=0) {
*code here what you want to happen when use is logged in*
} else {
*code here what you want to do when user isn't known*
}
When you want to display a login option for not logged in users which returns to the same page afterwards, you should add that stuff to the header of your page :
<?
header ("Pragma: no-cache");
header ("Cache-Control: no-cache, must-revalidate, max_age=0");
header ("Expires: 0");
?>
Keep in mind that this only works when the page you call glboal.php from is in the same directory as the global.php itself ... if not, you should just do a chmod (like 'chdir("/paths/to/your/frums");' ... just don't forget to jump back to the initial directory after you included the global.php then!
Like I said at the beginning, there might be thousands ways to do that better ... but hey, it works :)
Best regards,
Bobbi
SystemLogic
09-16-2001, 03:02 PM
Well for unregistered users, there is a a variable called $unregwelcomemessage in the forumhome template. There is also a template called forumhome_unregmessage. What about setting something up in that matter, basically the same exact thing, just rather than unregmessage, a new one called like loggedin_message or something?
Admin
09-17-2001, 12:31 PM
In index.php replace this:
$unregwelcomemessage='';
if ($bbuserinfo['userid']==0) {
eval("\$unregwelcomemessage = \"".gettemplate('forumhome_unregmessage')."\";");
}
with
$welcomemessage='';
if ($bbuserinfo['userid']==0) {
eval("\$welcomemessage = \"".gettemplate('forumhome_unregmessage')."\";");
} else
eval("\$welcomemessage = \"".gettemplate('forumhome_regmessage')."\";");
}
Now delete $unregwelcomemessage from your forumhome template and place $welcomemessage instead.
Also create a template named forumhome_regmessage and use it for messages for logged in users.
SystemLogic
09-18-2001, 06:48 PM
Thanks, that worked perfectly. You made a little mistake in your code for anybody that would like to use this. You did this:
$welcomemessage='';
if ($bbuserinfo['userid']==0) {
eval("\$welcomemessage = \"".gettemplate('forumhome_unregmessage')."\";");
} else
eval("\$welcomemessage = \"".gettemplate('forumhome_regmessage')."\";");
}
It should actually be:
$welcomemessage='';
if ($bbuserinfo['userid']==0) {
eval("\$welcomemessage = \"".gettemplate('forumhome_unregmessage')."\";");
} else {
eval("\$welcomemessage = \"".gettemplate('forumhome_regmessage')."\";");
}
You forgot the { after else, otherwise it gives a parse error.
Thanks again
Admin
09-19-2001, 04:25 AM
Damn brackets... :rolleyes:
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.