zeusthegreat Posted July 12, 2011 Report Share Posted July 12, 2011 have a website but wish to see how many people are visiting my site just want a simple script could do with a calendar aswell one that goes over a 12 month period thankyou lots of the freebies are crap out there. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 12, 2011 Report Share Posted July 12, 2011 Something that displays the number of users currently online within the website so visitors can see it too? Or are you just looking for statistics on who is visiting your site? If it's just analytics you are after that you don't need to show to anyone, Google Analytics should work fine. Quote Link to comment Share on other sites More sharing options...
zeusthegreat Posted July 12, 2011 Author Report Share Posted July 12, 2011 Something that displays the number of users currently online within the website so visitors can see it too? google Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 12, 2011 Report Share Posted July 12, 2011 I can't really recommend a specific script, since I've never had need for this functionality. That said, you might look at these tutorials: http://www.mikebernat.com/blog/Creating_a_Users_Online_Script_using_PHP http://php.inc.ru/main.php?t=p_active&view=tutorials Quote Link to comment Share on other sites More sharing options...
Archadian28 Posted July 13, 2011 Report Share Posted July 13, 2011 (edited) Hopefully you use $_SESSIONS for the login. You could store their username or somekind of unique ID, probably IP address to a $_COOKIE and check it against the Database on your script and make an online column in the users table and set it to 1 if they are online and 0 if they are not. And do something like this: if (isset($_COOKIE['online'])) { foreach($_COOKIE as $key => $value) { // key being "online" ex. $_COOKIE['online'] with their username stored // db connection $sql = "SELECT username FROM users WHERE username='$value'"; $result = mysql_query($sql); $row = mysql_fetch_object($result) while ($row->online == 1) { // echo $row->username or do a count and echo the number if users online } while ($row->online != 1) { // echo offline users (optional) } } } Im not sure how effective that code is and i would most definitely use mysqli if possible but that should get you headed in the right direction. You would have to run that script everytime one of your pages loads and reloads to check for online users every second. I would suggest putting the code in a function and returning $row->username or the number of users online then use javascript to delete the cookie on window.close and create it again at login. Of course at login when you create the online $_COOKIE update the online column to 1 and in the script above if the username in the cookie does not match the usernames in the table set online to equal 0. There are a few steps im leaving out probably but i think you get the idea . Also setting the time to 0 in setcookie() make it behave like a session. The cookie will delete on the browser close instead of using javascript to check the window.close. Edited July 13, 2011 by Archadian Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.