I use this piece of code to update the number of views a file has received.
[code=php]
/* Update views. */
$sql_update = “UPDATE dukkie_script SET views = views + 1 WHERE file = ‘” . $_GET[‘file’] . “‘”;
@mysql_query ($sql_update);
When viewing this page in IE or Opera everything is fine and with every click the number of views is updated by one, but when viewing the page in Firefox the number of views is updated by two for every click.
I’ll give some more info about how the page is included since I doubt anyone would know a fix for this problem.
When someone clicks a link ([url]http://www.mywebsite.com/viewfile/viewsource/testfile
a .htaccess rewrites the link to:
[url]http://www.mywebsite.com/index.php?url=viewfile&view=source&file=testfile
using this RewriteRule:
RewriteRule ^viewfile/viewsource/([0-9a-zA-Z-]+)/?$ index.php?url=viewfile&view=source&file=$1
Then the index.php includes viewfile.php and with a simple if ($_GET[‘view’] == “source”) the script knows that is has to print out the source of the file. Then if the file exists:
[code=php]
if (file_exists (“/path/to/file/” . $_GET[‘file’]))
{
// update page and use highlight_file () to view the source of $_GET[‘file;’]
}
Everything works fine, but the only problem I have is that in Firefox a view gets updated twice. I’m thinking of a bug, but maybe I’ve done something really dumb. So any help is welcome.