irkevin Posted October 27, 2007 Share Posted October 27, 2007 even if i'm new to php, so far i managed to write a who is online script.. but it's giving me a headache.. dunno whats wrong with it.. I have two tables.. one for guest(guest_online) and one for members(mem_online) the code for the guest is working just right but the one to insert the member if he is logged in is not working as it should.. When i logged in, it insert the username in the mem_online table, but when i refresh the page, it keeps incrementing the members.. here's the code <?php session_start(); include('config.php'); include('functions.php'); $ip = $_SERVER['REMOTE_ADDR']; $time = time(); $time_check=$time-60; //SET TIME 5 Minute mysql_connect($server,$dbusername,$dbpassword); mysql_select_db($db_name); $sql = "SELECT * FROM guest_online WHERE ip = '$ip'"; $result = mysql_query($sql); //check to see if there's a row if(mysql_num_rows($result) == 1){ $sql1 = "UPDATE guest_online SET time = '$time' WHERE ip = '$ip'"; $result1 = mysql_query($sql1); }else{ $sql2 = "INSERT INTO guest_online(ip,time)VALUES('$ip','$time')"; $result2 = mysql_query($sql2); } //end $sql3="SELECT * FROM guest_online"; $result3=mysql_query($sql3); $count_user_online=mysql_num_rows($result3); echo "Guest : $count_user_online "; // if over 10 minute, delete session $sql4="DELETE FROM guest_online WHERE time<$time_check"; $result4=mysql_query($sql4); // here is the code to insert the members if he is logged in if(isset($_SESSION['user_name'])) { $day=date('U'); $sql5 = "INSERT into mem_online VALUES('','$mem','$day','$ip')"; $result5 = mysql_query($sql5); } $sql6 = "SELECT * FROM mem_online"; $result6 = mysql_query($sql6); $memonline = mysql_num_rows($result6); echo "<br>Members : $memonline "; ?> I tried to log in, and everytime is refresh the page, it keeps inserting my username and Members keeps increasing. Why is it so? Can someone help? Quote Link to comment https://forums.phpfreaks.com/topic/74963-little-issue-with-this-who-is-online-code/ Share on other sites More sharing options...
teng84 Posted October 27, 2007 Share Posted October 27, 2007 maybe when you refresh the post data is still there im assuming you get a message something like "post data" Quote Link to comment https://forums.phpfreaks.com/topic/74963-little-issue-with-this-who-is-online-code/#findComment-379073 Share on other sites More sharing options...
irkevin Posted October 27, 2007 Author Share Posted October 27, 2007 Nopes i don't get this kind of message Quote Link to comment https://forums.phpfreaks.com/topic/74963-little-issue-with-this-who-is-online-code/#findComment-379075 Share on other sites More sharing options...
teng84 Posted October 27, 2007 Share Posted October 27, 2007 if you dont use post data then i guess the prob is that u dont have a validation maybe you can try $_SERVER['HTTP_REFERER'] to know if the user is form that page and or refresh the page something like if ($_SERVER['HTTP_REFERER'] == your page){//dont update} Quote Link to comment https://forums.phpfreaks.com/topic/74963-little-issue-with-this-who-is-online-code/#findComment-379077 Share on other sites More sharing options...
irkevin Posted October 27, 2007 Author Share Posted October 27, 2007 I dont really get this part. How would i implement this with my code ??? :'( When i logged in with my username and password.. it shows one member, and when i refresh it shows two and keeps increasing. I would like to try the $_SERVER['HTTP_REFERER'] but don't know how to use it :-\ Quote Link to comment https://forums.phpfreaks.com/topic/74963-little-issue-with-this-who-is-online-code/#findComment-379084 Share on other sites More sharing options...
teng84 Posted October 27, 2007 Share Posted October 27, 2007 $_SERVER['HTTP_REFERER'] <-- determine what is the last page that user visited sample your form index.php and you go to teng.php and you echo $_SERVER['HTTP_REFERER'] that should give you index.php the logic i see is that once your form index.php and you refresh the page the value of $_SERVER['HTTP_REFERER'] is index.php does it make sense Quote Link to comment https://forums.phpfreaks.com/topic/74963-little-issue-with-this-who-is-online-code/#findComment-379085 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.