| | |
Dani Webs Code?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
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.
Last edited by cscgal; Jan 16th, 2007 at 4:24 am. Reason: Typo
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
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.
p.s My templet for board index forum row. Where I have 'New topic' link is where I want Users Browsing
p.s users browsing [forum/topic] is written in php my board
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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}: {$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
Last edited by Inny; Jan 16th, 2007 at 4:33 am.
![]() |
Similar Threads
- Code tags whine-a-thon (DaniWeb Community Feedback)
- Problem with a Code Snippets present in (DaniWeb Community Feedback)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: IE problem - Something's wrong with this JS
- Next Thread: dynamically filling dropdown from another dropdown
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets api autoplay blackjack browser bug captchaformproblem checkbox child class close codes cookies createrange() cursor date debugger dependent developer disablefirebug dom dropdown editor element embed engine events explorer ext file flash form forms game getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl maps math matrixcaptcha media mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming progressbar rated runtime safari scriptlets scroll search security session shopping size software star stars stretch synchronous tweet unicode variables web webkit webservice window wysiwyg \n






