View Full Version : include the $loggedinusers on a non VB page?
I would like to include the $loggedinusers on a non VB page.
I assume that writing this data to a TXT file (and inserting it via SSI) everytime this data is modified would be a PAIN for the server as it may change several times per second when traffic is high... SO... what do you suggest?
Any of you guys could help?
I think that several peopel are trying to integrate vBulletin to sites as much as possible... I think that designwise it is the BEST board (onlineDJ.com looks great with the board, perfect integration) but it would be great to have an easy step by step help to show data to non VB pages, and to easily use the login of the board to other parts of the site.
this goes back to asking for a few include files to be made by the developers. would be nice.
ManoOne, the only ways to do it are 1) use an include or 2) have the page a .php page with a direct call to the mySQL database quering number of online users. Up to you which you do, as an include file is basically exactly the same i would not think there is much of a performance difference.
interesting
what would be the PHP code to add to the page (i can set th ephp extension to it) in order to grab those numbers from the database and display them?
thanks
not sure but it will be the same as the bit on index.php so it is probably in there somewhere.
THANK YOU SO MUCH!
http://www.onlinedj.com
Look, the frontpage of the site! Users are logged in once they enter the domain, etc. etc..
excellent, thanks again
I would also like to show who is on the board form my home page. It would be no biggie for me o make it a php page.
Can you please explain how to do it.
Thanks!
i am not sure, this may work:
$datecut=time()-$cookietimeout;
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session");
$totalonline=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid=0");
$numberguest=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid<>0");
$numberregistered=$loggedins[sessions];
$numbervisible=0;
$loggedins=$DB_site->query("SELECT DISTINCT user.userid,username,session.location FROM user,session WHERE session.userid=user.userid AND session.userid<>0 AND invisible=0 ORDER BY username");
if ($loggedin=$DB_site->fetch_array($loggedins)) {
$numbervisible++;
$userid=$loggedin[userid];
$username=$loggedin[username];
$location=$loggedin[location];
eval("\$activeusers .= \"".gettemplate("loggedinuser")."\";");
while ($loggedin=$DB_site->fetch_array($loggedins)) {
$numbervisible++;
$userid=$loggedin[userid];
$username=$loggedin[username];
$location=$loggedin[location];
eval("\$activeusers .= \", ".gettemplate("loggedinuser")."\";");
}
}
$numberinvisible=$numberregistered-$numbervisible;
eval("\$loggedinusers = \"".gettemplate("loggedinusers")."\";");
but then you will have to add this at the top
require("global.php");
it will also mean people on that page will be counted in the online stats
ManoOne
can you post your coding?
ManoOne, glad you got it working and glad i could help.
Mental Stamina, is must be something like what i posted because that is what i suggested to ManoOne who got it to work, the section you want is in index.php just make sure you require global.php at the top. try it it may well work :)
Guys.. I almost have it working I guess..
Here is the thing.. It dosent display..I viewed sorce..and the code stops at the
<?php
require("global.php");
?>
Hmm what do you think is happening?
I am calling this page:
http://www.clubfreestyle.com/testwho.php
Any ideas?
we need testwho as a .txt file or it just opens.
Hi Chrispadfield.. I dident know if it was ok to post my code here...but this is what it looks like:
<html>
<HEAD>
<!-- Start Who's Online -->
Who's online Now:<br>
<?php
require("forum/global.php");
$datecut=time()-$cookietimeout;
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session");
$totalonline=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid=0");
$numberguest=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid<>0");
$numberregistered=$loggedins[sessions];
$numbervisible=0;
$loggedins=$DB_site->query("SELECT DISTINCT user.userid,username,session.location FROM user,session WHERE session.userid=user.userid AND session.userid<>0 AND invisible=0 ORDER BY username");
if ($loggedin=$DB_site->fetch_array($loggedins)) {
$numbervisible++;
$userid=$loggedin[userid];
$username=$loggedin[username];
$location=$loggedin[location];
eval("\$activeusers .= \"".gettemplate("loggedinuser")."\";");
while ($loggedin=$DB_site->fetch_array($loggedins)) {
$numbervisible++;
$userid=$loggedin[userid];
$username=$loggedin[username];
$location=$loggedin[location];
eval("\$activeusers .= \", ".gettemplate("loggedinuser")."\";");
}
}
$numberinvisible=$numberregistered-$numbervisible;
eval("\$loggedinusers = \"".gettemplate("loggedinusers")."\";");
?>
<!-- End Who's onlone -->
</HTML>
It is retrieving the information just fine, but you do not have anything telling it to output the values of the variables.
Add:
echo $loggedinusers;
after
eval("\$loggedinusers = \"".gettemplate("loggedinusers")."\";");
Ben
Hi Ben,
I just added that in...still nothing. I think it's not even grabbing the global.php for some reason.
This file is in my root, and global is in /forum/global.pgp
so i put that code in like this:
require("/forum/global.php");
but still nothing.. An error message would be nice :-)
Stumped.
JackG
ClubFreestyle.com
it would post an error if it was not finding the file.
i thought it must be the output thing and was about to try it out but my ftp program keeps crashing so going to have to restart.
i will try again tomorrow to see if i can get it to work.
I'm new to PHP so I could be incorrect, but my thoughts are is that the code in "global.php" is trying to run in your HTTP root, and cannot find files that it needs. (Which are located in forum/admin).
I would suggest doing the following in order to get the user login information on your main page:
Step 1:
Create a file in your HTTP root named something like index_test.php and put this code in it:
<HTML>
<HEAD>
</HEAD>
<BODY>
Who's online Now:<BR>
<?php
chdir ("forum/");
require("testwho.php");
chdir("../");
/>
</BODY>
</HTML>
Step 2:
Put the file "testwho.php" into your /forum directory. The file should be changed to look like this: (Same as before, just removed the normal HTML parts, and the require statement uses the current path)
<?php
<!-- Begin Who's online -->
require("global.php");
$datecut=time()-$cookietimeout;
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session");
$totalonline=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid=0");
$numberguest=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid<>0");
$numberregistered=$loggedins[sessions];
$numbervisible=0;
$loggedins=$DB_site->query("SELECT DISTINCT user.userid,username,session.location FROM user,session WHERE session.userid=user.userid AND session.userid<>0 AND invisible=0 ORDER BY username");
if ($loggedin=$DB_site->fetch_array($loggedins)) {
$numbervisible++;
$userid=$loggedin[userid];
$username=$loggedin[username];
$location=$loggedin[location];
eval("\$activeusers .= \"".gettemplate("loggedinuser")."\";");
while ($loggedin=$DB_site->fetch_array($loggedins)) {
$numbervisible++;
$userid=$loggedin[userid];
$username=$loggedin[username];
$location=$loggedin[location];
eval("\$activeusers .= \", ".gettemplate("loggedinuser")."\";");
}
}
$numberinvisible=$numberregistered-$numbervisible;
eval("\$loggedinusers = \"".gettemplate("loggedinusers")."\";");
echo $loggedinusers;
?>
<!-- End Who's online -->
Basically what is happening is the index_test.php file changes to the forum directory and runs the testwho.php file. The testwho.php file can now correctly get global.php, and in turn the global.php file can correctly retrieve the files it needs from the forum/admin directory. After this is all done, index_test.php changes back to the root again where it started.
Try running index_test.php from your HTTP root directory and see what happens...let me know if that does not work. I'm pretty new to PHP, so my method of doing this is probably more of a rigged fix than the proper way, but it's all I can figure out at the moment.
Ben
Hrmm.. I get this error:
Fatal error: Cannot redeclare class db_sql_vb in /www/egamers/forum/admin/db_mysql.php on line 25
Any ideas?
Nevermind! I'm an idiot again.. I had a require("global.php"); in 2 files.. the file1 calls for global.php & file2.. file2 calls for global.php also
[Edited by _ on 01-02-2001 at 10:55 PM]
Sounds like the global.php file is being included twice. For the last info I posted the "require("global.php"); should only occur once.
Ben
I think if you create a new template say called "activeusers" and put something like this into it...
############
<br>
<table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
<TR bgcolor="#6c6081" id=cat><TD colspan=6>
<FONT face="verdana, arial, helvetica" size="2" color="#f5d300"><B>Currently Active Users:</B></font><br><FONT face="verdana,arial,helvetica" size="1" >There are currently $numberregistered member(s) and $numberguest guest(s) on the boards.</font></td>
</tr>
<tr>
<td>
<table width="100%%" border="0" cellpadding="2" cellspacing="0" bgcolor="#DEDEDE">
<tr>
<td align="left" valign="middle"><FONT face="verdana,arial,helvetica" size="1" >$activeusers</font></td>
</b></font></td>
</tr>
</table>
</td>
</tr>
</table>
############
Then call it with....
###########
eval("echo dovars(\"".gettemplate("active users")."\");");
###########
It may work ????
I tested Wajones plan and it worked!
Thanks bmurray ! Your method works.
Do you think this would cause an big extra load on my NT server by doing this on the home page?
It displays fine:
(look to the lower right for a ruff test)
http://www.clubfreestyle.com/newdefault.php
the problem is...when you click on a user..The url os a dead link because it tries to go to:
http://www.clubfreestyle.com/member.php?action=getinfo&userid=2
instead of the correct link:
http://www.clubfreestyle.com/forum/member.php?action=getinfo&userid=2
Bmurray..I just realized that if you are not logged into the system..and you go to that page..
It actually gives an error. Please check.
How can we avoid that?
To get correct links, you will have to use a different template in the code on the main page. Create a template called "loggedin_new" (or anyname you prefer), and change the link so that it puts a forum/ in it.
Add template - loggedin_new
<a href="forum/member.php3?action=getinfo&userid=$userid">$username</a>
Then change any reference to the template "loggedinuser" to "loggedin_new" in your code. Just make sure you don't confuse it with the other template "loggedinusers" that has an "s" at the end.
Let me know how that works
Hmm...I'll have to check that out regarding the not logged in error...I'll get back to you
I think it is trying to create cookies, but the code is being executed in the incorrect order in relation to the rest of the page.
I'm not sure how you have the PHP page set up currently, but try putting this part:
<?php
chdir ("forum/");
require("testwho.php");
chdir("../");
/>
at the very beginning of your newdefault.php file. Then go into the "testwho.php" file and remove the statement
echo $loggedinusers;
and instead place
<?php
echo $loggedinusers;
?>
in the newdefault.php file where you want it displayed.
Unfortunately I'm at work and have no way to test to see if this works before posting.
Let me know what happens
Good Job! I can now see whos online without being loged in!
Next i will try to fix the hyerlink problem. i will keep you posted. Many Many Thanks!
Ben,
Everything you suggested works fine! Check it:
http://www.clubfreestyle.com/newdefault.php
(keep in mind that you might see some broken images, etc.. That page is just a test page so please disreguard it's appearance.)
You Da Man!
Please keep in touch.
please look at:
http://www.halflifeworld.net and tell me what im doing wrong.
The Red and yellow table sholdnt be there, and the $loggedin_new is not showing up.
MonkeyManx - it appears you need to move the code to the beginning of your index file. To make it simpler and because this has changed since my first post with info, I redid the instructions for getting this to work and put it in a text file:
loggedin.txt (http://www.houseofkarana.com/hacks/loggedin.txt)
After some trial and error, this should contain what is needed to get it work properly. Keep in mind this isn't a "hack" so to speak, and at some point when I have time I am going to try to refine it a little bit to work more efficiently.
wow, it works! thanks a bunch!
MonkeyManx -
I checked out your page, and you seem to still have a problem with errors showing up for users without a cookie. Check to make sure that the following part of the code from the textfile I posted is before any HTML in index.php.
<?php
// Changes to forum directory, runs "usersonline.php", and changes back
chdir ("forums/"); // Change "forums/" to reflect your vBulletin directory if it is different
require("usersonline.php");
chdir("../");
?>
Other than that, it looks like it fits in real nicely with the rest of the page :)
oh my god.. this thread is still going!
all i did really... I created a copy of the index.php, called it frontpage.php
at the end, i changed the echo to be "frontpage" instead of calling the template "forumhome"
then i created a template called "frontpage" with all my custom layout
then I edited the global.php file to make "frontpage" and other templates readable from any of the vBulletin pages
and.. it WORKS!
>>>> http://www.onlineDJ.com
Originally posted by ManoOne
then I edited the global.php file to make "frontpage" and other templates readable from any of the vBulletin pages
and.. it WORKS!
>>>> http://www.onlineDJ.com
Hi, Can you specify what you did to global.php exactly?
I am using a different method which is causing some problems...would like to do it your way.. P.S. Phat Site!
Peace.
Originally posted by JackG
would like to do it your way.. P.S. Phat Site!
:D THANKS!
Well.. let me see... you only need to create a copy of index.php and call it sitefrontpage.php for example... then edit the last line to pull a new template instead of the "forumhome" template (echo line).
create your custom frontpage, you can start from the HTML code of the template "forumhome" to keep all the reg members count and all... and add your own design to it..
voila
not harder than this
Thanks for the comments again, feel free to join sometimes if you are into music (not just DJs, also composers and other performers are posting).
take care
THanks allot manoOne for taking the time to explain. I think I capish. Will try it tomorrow.
FYI.. I am already display who's online on my home page thanks to Ben. What I was hoping to do is log a user in when they enter the main page.. I am asuming your method dies this?
About your site.. I sent my partner there..he is New York's #1 freestyle music DJ (on WKTU 103.5). Said he loves it.
Keep up the good work on your site, Mine is similar..except it is all about freestyle music.
The cool thing is that many artists and producers are regulars. Eveyone loves the brand new vBulletin I installed.
Take care.
[Edited by JackG on 01-11-2001 at 03:23 AM]
that's great, man.
I appreciate the comments, thanks.
I like your site too. I clicked everywhere :)
See you soon
small problem
why does http://halflifeworld.net display an error and http://www.halflifeworld.net works fine? Anyone know?
place this in your global.php
~~~~~~~~~~
// ###################### Check Usersonline #######################
$vars=$DB_site->query("SELECT user.username, user.userid FROM user, session WHERE session.userid=user.userid");
while($var=$DB_site->fetch_array($vars)) {
$varcache["{usersonline}"] .=' <a href="member.php?action=getinfo&userid='.$var[userid].'">'.$var[username].'</a>';
}
~~~~~~~~~~
require global.php
place in your templates {usersonline} (the replace variable)
e.g.:
usersonline.php
~~~~~~~~~~
<?
require("global.php");
eval("echo dovars(\"".gettemplate("usertest")."\");");
?>
~~~~~~~~~~
template usertest
~~~~~~~~~~
<table>
<tr>
<td>{usersonline}</td>
</tr>
</table>
~~~~~~~~~~
sorry for the bad english i am a german guy :)
Originally posted by ManoOne
THANK YOU SO MUCH!
http://www.onlinedj.com
Look, the frontpage of the site! Users are logged in once they enter the domain, etc. etc..
excellent, thanks again
can you teach me how that was done??
i explained it in some post in this thread
so ManoOne... Your web site home directory is in your forum root?
I wanted to have this page (my home page) outside of the forum root (folder)..
Wondering if it will still work if I change
all the paths.
Bringing it back from the dead....
if a person visits my main page, will it mark thier forums read if s/he doesn't visit the forums?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.