Jump to content

extremely unclear fault with script


Alex007152

Recommended Posts

Hi,

 

I've desperately searched on this one for hours and it has frustrated me to no end. I've contacted my webhost, posted it on the firefox forums but they all point at the script self. Here's the code:

 

$TopicID = (get_magic_quotes_gpc()) ? $_GET['Topic'] : addslashes($_GET['Topic']);
mysql_query("UPDATE topics SET topic_views=topic_views+1 WHERE topic_id=$TopicID");

 

It's so simple and short and can yet cause so such a headache. The point of it is to increment the amount of views of a topic with ONE. MSIE7 seemed to increment correctly, FireFox not. I'm going to test more browsers but really, there is absolutely no logical reason on why the field topic_views gets incremented with random numbers ranging from one to four with firefox. I've tested this code on an empty seperate page and it worked fine, but the origional code is just as isolated from the rest of the code as on the seperate page. Any ideas? I'd eat my shoes if this is really due to my own code.

Link to comment
Share on other sites

Doubt this will fix your current problem (Could be wrong) but when you're using "WHERE this=$that", it's good practice to put the value in single quotes like this...

 

<?php

mysql_query("UPDATE `topics` SET topic_views=topic_views+1 WHERE topic_id='$TopicID'");

?>

 

And also putting the backticks around the table names isn't going to hurt overall. Would be amusing if that solves it for you.

Link to comment
Share on other sites

only +1 here, i think it is a firefox issue

 

I was thinking that aswell, but heres a responce from someoone from the firefox forums:

 

There is no possible way that server-side code, including the block you posted, can be affected by the client. Well .. it could be possible if data is passed from server to client and back, or client to server. This is not your case, and although in IE your code works correctly, I would be checking somewhere else. Maybe the functions in your code look for the useragent, and then respond differently if the user is not IE? That would be my guess.

 

Only the HTML code that is created by your server's PHP code, is processed by Firefox. Firefox doesnt process php itself.

Link to comment
Share on other sites

Has to deal with mozilla firefox's about:config settings

 

network.http.max-persistent-connections-per-server

 

That value is user set on the browser. Meaning that firefox will request the page x times.

 

I changed my value to 1 and it worked fine but before when it was 2 it increased your views by 2 each actual view.

Link to comment
Share on other sites

Has to deal with mozilla firefox's about:config settings

 

network.http.max-persistent-connections-per-server

 

That value is user set on the browser. Meaning that firefox will request the page x times.

 

I changed my value to 1 and it worked fine but before when it was 2 it increased your views by 2 each actual view.

 

Thanks ALLOT for pointing that out! I'm just not sure how to write a script that deals with it though, any suggestions?

Link to comment
Share on other sites

Hi again, i looked up some code on my old PHPBB forum, heres the part that increments the 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);
}

 

It works fine, apparantly, no matter how high "network.http.max-persistent-connections-per-server" is set. According to another member from the firefox forums, it also has something to do with empty src attributes with images, making standard browsers load the page multiple times. Checked all src attributes and everything was fine however. Any idea's on how to work around it?

Link to comment
Share on other sites

Are you including the file that does the incrementing, in on another php file?

 

No. I tried that but it obviously had the same result. I'm going on vacation tomorow, it's too bad i didn't had the time to fix it before i have to go but i'll be looking on internet for information on the bug on internet clubs orso. I urgently need to find a way to get this to work because i'm afraid i can't continue the development of my site without having this fixed. I'd extremely highly appreciate it if someone could tell a way to work around it.  :)

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.