Inserting rows twice

So I modified logger.php so that it inserts the data into a MySQL database instead of the log file. Its all working fine except its inserting two rows with identical information and timestamps except for the downloadSpeed and uploadSpeed columns. One row has 0 and 0 while the other row has the actual speeds.

If I navigate to logger.php manually, it adds the single row properly (with 0 and 0 for the up/down speeds because the test wasn’t run and $_POST is empty) but if I perform the speed test, it behaves as noted above.

Here is the modified logger.php file:

Code:

<!– echo –>
<!– Do not remove the echo comment above or speeds will not be recorded –>
<?
if (isset($HTTP_POST_VARS['testspeeds']))
{
$testspeeds = $HTTP_POST_VARS['testspeeds'];
$speeds = explode("t", $testspeeds);
$info['downloadSpeed'] = $speeds[0];
$info['uploadSpeed'] = $speeds[1];
} else {
$info['downloadSpeed'] = 0;
$info['uploadSpeed'] = 0;
}

if (isset($_SERVER['REMOTE_ADDR']))
{
$info['ip'] = $_SERVER['REMOTE_ADDR'];
} else {
$info['ip'] = getenv(‘REMOTE_ADDR’);
}

if (isset($_SERVER['HTTP_USER_AGENT']))
{
$info['browser'] = $_SERVER['HTTP_USER_AGENT'];
} else {
$info['browser'] = "";
}

if (isset($_SERVER['PHP_SELF']))
{
$info['page'] = $_SERVER['PHP_SELF'];
} else {
$info['page'] = "";
}

if (isset($_SERVER['HTTP_REFERRER']))
{
$info['referrer'] = $_SERVER['HTTP_REFERRER'];
} else {
$info['referrer'] = "";
}

require(‘PATHTOFILEWITHUSERNAMES’);
require_once(‘../include/mySQL.php’);
$db = new mySQL($logsUser, $logsPass);
$x = 0;
$cols = ‘(‘;
$vals = ‘(‘;
foreach ($info as $k => $v)
{
$x++;
$last = ($x == count($info)) ? true : false;

$cols .= "`{$k}`";
$vals .= "’{$v}’";

if (!$last)
{
$cols .= ‘, ‘;
$vals .= ‘, ‘;
}
}
$cols .= ‘)’;
$vals .= ‘)’;

$sql = "INSERT INTO `logs` {$cols} VALUES {$vals}";
$db->selectDatabase(‘MYDATABASE’);
$db->query($sql);
unset($db);
?>

Any insight would be greatly appreciated.

Comments

  1. AMPC says:

    Hi Keith,

    I am aware of the problem and don’t have a solution as of yet. I’m considering releasing the flash speed test as open source as I don’t have time to care for it like I should, but this is just a thought.

    I’ll try to take a look at this when I get a little time.

    Best regards,

    Jim.

  2. Keith says:

    Oh good, at least I know that its a known issue.

    I wonder what is triggering it though.. I’m not a flash developer, but it appears that mostly you just pass the speed results to the $_POST variable. It seems to work fine the way you originally had the logging. What about the modified script is triggering it?

  3. AMPC says:

    It’s on my list and good question!

    Thanks,

    Jim.

Speak Your Mind

Comment moderation is enabled. Your comment may take some time to appear.