PDA

View Full Version : Show Mods And Admin on Non-vb PHP Page


Mile-O-Phile
03-17-2005, 11:43 AM
I have a line on my home page that offers links to various parts of my site (i.e. Home, News, Links, Resource, Quizzes, etc.) but I would like to add a further section to the line (namely 'Admin') that will only appear in the list if one of the people browsing the page is either myself or one of the moderators from my forum.

How could I do this?

sabret00the
03-17-2005, 06:08 PM
if it's a vB-powered page then you can use the is_member_of function() in a conditional :)

alternatively you can go old school with

if ($bbuserinfo['usergroupid'] == 6 OR $bbuserinfo['usergroupid'] == 7 or $bbuserinfo['usergroupid'] == XX)
{
your block of code here
}


the same applies if you're using templates too.

Mile-O-Phile
03-18-2005, 07:16 AM
if it's a vB-powered page then you can use the is_member_of function() in a conditional :)

alternatively you can go old school with

if ($bbuserinfo['usergroupid'] == 6 OR $bbuserinfo['usergroupid'] == 7 or $bbuserinfo['usergroupid'] == XX)
{
your block of code here
}


the same applies if you're using templates too.
Thanks, but as the title of the thread states, it's a non-vb page. It's my index.php of my main site.

sabret00the
03-18-2005, 07:59 AM
then in that case check the session.php see if it defines the usergroup in the cookies and then use $_COOKIE['usergroupid'] :)

alternatively you could include the vb-global.php just for that piece of code.

Mile-O-Phile
03-18-2005, 08:01 AM
then in that case check the session.php see if it defines the usergroup in the cookies and then use $_COOKIE['usergroupid'] :)

alternatively you could include the vb-global.php just for that piece of code.
Thanks again, but my knowledge of PHP is limited to passing a variable to a page and if...else... constructs.

vBulletin's structure is way beyond my understanding.

What steps are necessary to do this? :(

sabret00the
03-18-2005, 08:27 AM
chick this with marco or someone else that will come in this thread but


rest of your page;

include("forums/global.php");
code i showed you before;
unset("forums/global.php"); //not sure if you can unset a file like that that's why you need a master coder in here
more of your page;

Marco van Herwaarden
03-18-2005, 08:42 AM
No you can NOT use unset on a file, only on a variable. (lol not a master coder myself ;) )
chick this with marco
Hmm a nice chick :D

Mile-O-Phile
03-18-2005, 10:55 AM
Well, I messed around with an example page. Just used this:

<?php
include("forum/global.php");
$admin = $_COOKIE['usergroupid'];
?>
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo $admin;
?>
</body>
</html>

The page is here (http://www.talk-history.com/example.php).

I got the following errors:

Warning: main(./includes/init.php): failed to open stream: No such file or directory in /home/linguami/public_html/forum/global.php on line 18

Fatal error: main(): Failed opening required './includes/init.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/linguami/public_html/forum/global.php on line 18

Now what? :confused:

Marco van Herwaarden
03-18-2005, 11:35 AM
Change to:
<?php
chdir("/home/linguami/public_html/forum");
include("./global.php");
....

Mile-O-Phile
03-18-2005, 11:39 AM
Change to:
<?php
chdir("/home/linguami/public_html/forum");
include("./global.php");
....

Thanks. I've now done that and I'm getting a blank HTML page. I added the world Hello to it like this:

<?php
chdir("/home/linguami/public_html/forum");
include("./global.php");
$admin = $_COOKIE['usergroupid'];
?>
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hello $admin";
?>
</body>
</html>

But the variable $admin isn't getting anything. I know there should be a cookie as I'm logged into my forum at the moment.

Marco van Herwaarden
03-18-2005, 01:38 PM
If i run teh same scipt (with my own path ofcourse) i get a blank page with only "Hello".

The reason for this is simply: usergroupid is not stored in the cookie.

Do the following instead instead of the echo $admin:
echo "Hello $bbuserinfo[usergroupid]";


If you want to know what more information is stored in the $bbuserinfo table, add a line like the following:
echo "<br />bbuserinfo: <pre>";print_r($bbuserinfo);echo "</pre>";

Mile-O-Phile
03-19-2005, 08:55 AM
That looks great. The only last thing seems to be that it is treating me as being a Guest/Unregistered on my own forum. I am currently logged in, however.