env3rt Posted October 3, 2007 Share Posted October 3, 2007 I need to know how to tell how many people are viewing your site. I imagine the code would be something like this: <?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views']+ 1; echo " <script type='text/javascript' for='window' event='onunload'> $_SESSION['views'] = $_SESSION['views']- 1; </script>"; echo "views = ". $_SESSION['views']; ?> (the above doesn't work) Unless there is a php onunload function.. please help Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 No, that won't work. Each user has their own session, and different sessions cannot directly interact with each other. What you would need to do is use session_set_save_handler. This will store all session data in a table in your database. You can then count the number of active sessions by querying that table. This not only allows extra functionality, but increases security, as well. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 3, 2007 Author Share Posted October 3, 2007 Is there a way to do it without tables (I don't like them) Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 I suppose you could do it with flat text files, but that would be very messy and difficult. session_set_save_handler would let you do it with text files as well. What is your aversion to using a database? Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 3, 2007 Author Share Posted October 3, 2007 I liked using php files more than databases because I don't like phpmyadmin or mysql cause I don't know how to use them. Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 Learn. Really, if your site is to store any information at all, you need a database of some kind. As far as liking "php files more than databases", it's not an either or type of thing. PHP is a hammer. A database is a drill. They're both extremely useful, but do completely different jobs. If you want work with PHP, learning to use a database is essential. 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.