Jump to content

Run script once


Alex007152

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.