0

Hi!
I have a counter that increments by 1 for every page view.

$colname_Recordset1 = "-1";
if (isset($_GET['urlcode'])) {
  $colname_Recordset1 = $_GET['urlcode'];
}
mysql_query("UPDATE users SET counter = counter + 1 WHERE urlcode = '$colname_Recordset1'");

It works in IE but counts twice in firefox the first time the page is viewed. If I call the page again it increments by 1 as programed.
It increments by 2 the first time the page is called.
Any suggestions or comments would be appreciated.
I'm starting to think maybe it's a problem with my computer.
Anyone ever experience something like this?

2
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by phpDave
0

No. Is FF loading the page twice? Place a javascript alert in your head script just to see if the page is being loaded twice.

<head>
<script>alert('loaded');</script>
...
</head>

Although it's php and runs before the js, I can't imagine that the server would run this script twice before sending to the browser. So this js should popup twice on FF and only once on IE otherwise. Strange though. Have you got any redirects?

Edited by diafol: n/a

0

Thanks again Ardav,
I ran the script, it only ran once. Again, the frist time I called the page the counter incremented twice, after that just once. There is not much on the page, no links, no redirects, but I do display the counter in the persons personal page.

0

Thanks again Ardav,
I ran the script, it only ran once. Again, the frist time I called the page the counter incremented twice, after that just once. There is not much on the page, no links, no redirects, but I do display the counter in the persons personal page.

Ok post the whole page

0

Note: I tried the counter script in a few different places.

<?php require_once('Connection/connadmin.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_GET['urlcode'])) {
  $colname_Recordset1 = $_GET['urlcode'];
}
mysql_query("UPDATE user SET counter = counter + 1 WHERE urlcode = '$colname_Recordset1'");

mysql_select_db($database_connadmin, $connadmin);
$query_Recordset1 = sprintf("SELECT user_id, link_one, link_two, link_three, link_four, link_five, link_six, area_one, area_two, area_three, area_four, area_five, area_six, status, user.date, DATE_FORMAT(user.date,'%%M %%e,%%Y')AS us_format FROM registration LEFT JOIN user USING(user_id) WHERE urlcode = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $connadmin) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>
<?php ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ROBOTS" content="NOINDEX" />

<title>Page</title>
<link href="small.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
if (screen.width >= '900'){
	document.write('<link href="main.css" rel="stylesheet" type="text/css" />');
}else {document.write('<link href="small.css" rel="stylesheet" type="text/css" />');
}
</script>
<style type="text/css">

<!--
body {background-color:#DDD;
}
-->
</style

><link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<script>alert('loaded');</script>
</head>

<body>
<div id="wrapper">
  <div id="header"></div>
  <div id="content">
  <div id="date"><strong>Last Updated:</strong> <?php echo $row_Recordset1['us_format']; ?></div>
    <div class="VTabbedPanels" id="center">
      <div id="TabbedPanels1" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0"><?php echo $row_Recordset1['link_one']; ?></li>
          <li class="TabbedPanelsTab" tabindex="0"><?php echo $row_Recordset1['link_two']; ?></li>
          <li class="TabbedPanelsTab" tabindex="0"><?php echo $row_Recordset1['link_three']; ?></li>
          <li class="TabbedPanelsTab" tabindex="0"><?php echo $row_Recordset1['link_four']; ?></li>
          <li class="TabbedPanelsTab" tabindex="0"><?php echo $row_Recordset1['link_five']; ?></li>
          <li class="TabbedPanelsTab" tabindex="0"><?php echo $row_Recordset1['link_six']; ?></li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="TabbedPanelsContent"><?php echo $row_Recordset1['area_one']; ?></div>
          <div class="TabbedPanelsContent"><?php echo $row_Recordset1['area_two']; ?></div>
          <div class="TabbedPanelsContent"><?php echo $row_Recordset1['area_three']; ?></div>
          <div class="TabbedPanelsContent"><?php echo $row_Recordset1['area_four']; ?></div>
          <div class="TabbedPanelsContent"><?php echo $row_Recordset1['area_five']; ?></div>
          <div class="TabbedPanelsContent"><?php echo $row_Recordset1['area_six']; ?></div>
        </div>
      </div>
    </div>
  </div>
  <div id="footer"></div>
</div>
<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
//-->
</script>
</body>
</html>

<?php
mysql_free_result($Recordset1);
?>
0

OK cut it to the bone - try this:

<?php require_once('Connection/connadmin.php'); 

$cr1 = "-1";

if (isset($_GET['urlcode'])) {
  $cr1 = $_GET['urlcode'];
}

mysql_query("UPDATE user SET counter = counter + 1 WHERE urlcode = '$cr1'");


//OK all the belowis just selecting. The stuff above is the impt
mysql_select_db(...);   

[WHY THE ABOVE? ARE YOU CHANGING DB?]


if($s != ''){
	mysql_real_escape_string($theValue);
}else{
	$s = "NULL";
}



$q = "SELECT user_id, link_one, link_two, link_three, link_four, link_five, link_six, area_one, area_two, area_three, area_four, area_five, area_six, status, user.date, DATE_FORMAT(user.date,'%%M %%e,%%Y')AS us_format FROM registration LEFT JOIN user USING(user_id) WHERE urlcode = $s";

$res = mysql_query($q) or die(mysql_error());
$tot = mysql_num_rows($res);
$data = mysql_fetch_assoc($res);
?>
0

OK! new info, makes more sense now.
First, thanks for your time and input!
Second, sorry I did not notice this before, but if I type the url or click on it as a link it increments by 1 as expected. When I'm testing, I have the url on a word document and when I click on link there it increments by 2 but only the first time I click on it. I use fire fox as my browser so that is the browser that loads the page, for IE I have to type in url and it worked.
So everything seems to work ok unless the link is on a word doc.
Any thoughts?

1

Well a quick Google gave me this:

http://www.knowledgesutra.com/index.php/problem-firefox-latest-version-loading-pages_t50645.html

Talks about having to load a page twice to get it to display. Seems that it is down to speed hacks or the Google toolbar.

AVG link checker may also cause problems. Perhaps there is a timeout and reload.

I've stopped using FF myself as it takes about 2 minutes to start up. I've just lost patience with it. I'm a Chrome convert. Anyway, my personal preferences doesn't address the problem does it.

How about setting a session script?

session_start();
if(!isset($_SESSION['runs']))$_SESSION['runs'] = 0;
$_SESSION['runs'] = $_SESSION['runs'] + 1;
echo "session runs = " . $_SESSION['runs'];

Place this at the start of the file. Place a link in the file to a new page called reset.php.

The reset.php file will just have the following:

<?php
session_start();
$_SESSION['runs'] = 0;
?>

This will turn the counter to 0 so you can retest the word link.

I really can't help more than that. Haven't really got a clue. Short of reinstalling FF. *sigh*

Votes + Comments
Very knowledgeable
0

Thanks for all the help. I know what direction to go in now!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.