This site shows (x) users veiwing each forum on the main index, Id love to know how its done? can it be done with javascript?

Recommended Answers

All 5 Replies

i think its a php script maybe
i know nothing about web design though so take that with a pinch of salt

Well thankyou for replying at all, Appreciated! :D

This forum uses PHP and the code is embedded into the software.

I do not know if it can be done with javascript.

It's not possible to do this with JavaScript because you would need some sort of database to keep track of how many visitors there are, which can only be done with a server-side programming language.

We do it with PHP and MySQL. Each time a page is accessed, a record in a MySQL table is updated with the user's IP address and the timestamp. Records with timestamps older than 20 minutes are deleted. The number of IP addresses is the number of people currently visiting the site.

ok Thanks again. I found a similar code that may need slight tweaking to work for me. I dont have a 'veiws' cell on my main index though.
could I rewrite this to add to cell 'Forum'? which list the forum name?

P.s Im aware of the advertising ban so I wont link you my site to see.

<script type="text/javascript">
<!--
/*
Users Viewing In Main Page 
*/
var addrequest;
var viewadds = new Array();
var curnum = 0;
var td = document.getElementsByTagName('td');
for(t=0;t<td.length;t++){
if(td[t].getElementsByTagName('a')[0] && td[t].getElementsByTagName('a')[0].href.match(/showforum=\d+/)){
viewadds.push(td[t]);
}}
checkBViews();
function checkBViews(){
if(window.ActiveXObject){
addrequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
addrequest = new XMLHttpRequest();
}
var opener = viewadds[curnum].getElementsByTagName('a')[0].href;
addrequest.onreadystatechange = function(){
addBViews();
}
addrequest.open("GET",opener,true);
addrequest.send('');
}
function addBViews(){
if(addrequest.readyState == 4 && addrequest.status == 200){
var resptext = addrequest.responseText;
var addiv = document.createElement('div');
addiv.innerHTML = resptext;
var hdiv = addiv.getElementsByTagName('div');
var views = 0;
for(a=0;a<hdiv.length;a++){
if(hdiv[a].className == "darkrow2" && hdiv[a].innerHTML.match(/^(\d+) User\(s\) are browsing this forum/)){
views = parseInt(RegExp.$1) - 1;
}}
if(views < 0){
views = 0;
}
if(views != 0){
var viewstext = document.createTextNode( ' ('+views+' viewing'+')');
viewadds[curnum].insertBefore(viewstext,viewadds[curnum].getElementsByTagName('br')[0]);
}
curnum++;
if(curnum != viewadds.length){
checkBViews();
} else {
termViews();
}}}
function termViews(){
if(window.ActiveXObject){
addrequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
addrequest = new XMLHttpRequest();
}
addrequest.open("GET",location.href,true);
addrequest.send('');
}
//-->
</script>

p.s My templet for board index forum row. Where I have 'New topic' link is where I want Users Browsing

<tr> 
          <td class="row4" align="center">{$info['img_new_post']}</td>
          <td class="row4"><a href="{ibf.script_url}showforum={$info['id'] }"onMouseover="ddrivetip('Open This Forum!','yellow', 150)";
onMouseout="hideddrivetip()"><b>{$info['name']}</b></a><br /><br><a href="{ibf.script_url}act=Post&CODE=00&f={$info['id']}"onMouseover="ddrivetip('Start A new Topic In this Forum!','yellow', 150)";
onMouseout="hideddrivetip()"><FONT COLOR="#FF0000"><b>New Topic</b></font></a><br /><br><span class='desc'>{$info['description']}<br />









</span></td>
         
          <td class="row2" align="center">{$info['topics']}</td>
          <td class="row2" align="center">{$info['posts']}</td>

  <td class="row2" nowrap="nowrap">{$info['last_post']}<br />{ibf.lang.in}:&nbsp;{$info['last_unread']}{$info['last_topic']}

<br />{ibf.lang.by}: {$info['last_poster']}

</td>
        </tr>

p.s users browsing [forum/topic] is written in php my board

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.