greekscientist Posted July 21, 2011 Share Posted July 21, 2011 I found a script at the net but it have a small mistake. I tried 3 hours but i can`t get it work. The problem is i believe at those lines $get_ip = mysql_query("SELECT * FROM ".$db_table." WHERE vis_ip=".$vis_ip." LIMIT 1"); while ($row=mysql_fetch_object($get_ip)) It doesn`t get inside the while to execute the next lines the whole script is that <?php // config variables $tframe = 1000; // time frame (minutes) to count active users // database connection details $db_host = "localhost"; // hostname of your MySQL server. You most likely don't have to change this $db_name = "**_fruits"; // database name $db_user = "**_apples"; // database user $db_pass = "**"; // database password $db_table= "visits"; // table name // Lets open up a connection to the database $db = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); // On to the counter processing... $vis_ip = ip2long($_SERVER['REMOTE_ADDR']); $time = time(); $new_vis = 1; // update database for returning visitor $get_ip = mysql_query("SELECT * FROM ".$db_table." WHERE vis_ip=".$vis_ip." LIMIT 1"); while ($row=mysql_fetch_object($get_ip)) { mysql_query("UPDATE ".$db_table." SET vis_time='$time' WHERE vis_ip='$vis_ip'") or die (mysql_error()); $new_vis = 0; } // add to database for new visitor if ($new_vis == 1) { mysql_query("INSERT INTO ".$db_table." (vis_ip, vis_time) VALUES ('$vis_ip','$time')") or die (mysql_error()); } // done processing the visit, now lets see how many total visitors are online $tcheck = time() - (60 * $tframe); $query = mysql_query("SELECT * FROM ".$db_table." WHERE vis_time > $tcheck"); $onlinenow = mysql_num_rows($query); // show number of visitors on screen if($onlinenow == 1) { echo"currently $onlinenow visitor online"; } else { echo"currently $onlinenow visitors online"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/ Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 i'm not going to start reading the code until I know what error(s) you are receiving.. Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245851 Share on other sites More sharing options...
greekscientist Posted July 21, 2011 Author Share Posted July 21, 2011 Hello and thanks for the interest! As i allready write "It doesn`t get inside the while to execute the next lines" I just provide the code because i think that is needed Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245857 Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 so you don't receive any errors at all in your error.log? Any mysql errors? Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245860 Share on other sites More sharing options...
greekscientist Posted July 21, 2011 Author Share Posted July 21, 2011 Basically the script should show the unique visitors. I upload it and tested it. O refresh the page and it count 1,2,3 + unique visitors. It should only show 1 unique visitors at that situation. The thing is that it doesn`t execute those code after the while loop. Is something like ... search sql table for a record. If its exist update it, if not insert new record. That script only enters new records. Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245863 Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 you're not understanding what im asking... http://inobscuro.com/tutorials/simple-php-unique-visitors-counter-30/ Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245870 Share on other sites More sharing options...
greekscientist Posted July 21, 2011 Author Share Posted July 21, 2011 I checked the logs and i dont have errors. I dont have mysql errors either. The problem is just the functionality edit: i want to learn what i do wrong, not to just copy another program Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245888 Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 your code needs alot of cleaning up and right now i'm too lazy to do it, like for instance you don't need a while loop if you are expecting only one output row for your query, makes no sense, and you can most certainly learn from someone elses script that works.. i never said copy and past it...i asked you a question 3 times and you just answered it now..pfff Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245898 Share on other sites More sharing options...
greekscientist Posted July 21, 2011 Author Share Posted July 21, 2011 i said from the beggining that it doesn`t enter the loop m8. Sorry if i become boring and thanks for your help. I will keep trying until i learn my mistake Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1245923 Share on other sites More sharing options...
jawadqureshi Posted July 28, 2011 Share Posted July 28, 2011 the best way is to try first. by the way it is very simple. Quote Link to comment https://forums.phpfreaks.com/topic/242574-visitors-counter/#findComment-1248545 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.