Alex007152 Posted July 19, 2007 Share Posted July 19, 2007 Hi, I started a thread on a firefox issue with a php script recently, i'm still stuck for example with this script to increment the views of a topic: mysql_query("UPDATE `forum_topics` SET topic_views=topic_views+1 WHERE topic_id='$TopicID'"); Firefox is probably not the only browser that loads pages more then once by default. The problem with this script for example is that i want it to increment the views once the visitor actually opens the topic, not when the browser loads it multiple times wich results in invalid views. So now i'm wondering if there's a way to run scripts on a page once, only when the visitor actually opens the page. I've tried include_once() but the browser included it twice anyway. Thanks allot in advance. Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 19, 2007 Share Posted July 19, 2007 There is no work around, i had the same problem with mine, it was firefox's problem, not your script. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 19, 2007 Share Posted July 19, 2007 Are these anonymous browsing users or "registered" users? Either way, if it's crucial to you, you could implement cookies to track which users have browsed which pages by associating a list of pages with a user's unique id/cookie. Users not accepting cookies would be immune, however. include_once() has nothing to do with how many times a user has visited the script, but how many times the included file is included in the script (once) on any given execution. Quote Link to comment Share on other sites More sharing options...
Alex007152 Posted July 19, 2007 Author Share Posted July 19, 2007 Are these anonymous browsing users or "registered" users? Either way, if it's crucial to you, you could implement cookies to track which users have browsed which pages by associating a list of pages with a user's unique id/cookie. Users not accepting cookies would be immune, however. include_once() has nothing to do with how many times a user has visited the script, but how many times the included file is included in the script (once) on any given execution. Thank you for the suggestion, i could try that if there is no other alternative way. There is no work around, i had the same problem with mine, it was firefox's problem, not your script. I have to disagree; PHPBB for instance seems to have worked around it somehow. This should be their code that increments the field topic_views: // // Update the topic view counter // $sql = "UPDATE " . TOPICS_TABLE . " SET topic_views = topic_views + 1 WHERE topic_id = $topic_id"; if ( !$db->sql_query($sql) ) { message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql); } I do hope however that it's indeed due to FireFox and that it will handle the code correctly.. 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.