Jump to content

insert on load with timestamp


a2bardeals

Recommended Posts

i am writing a stat cruncher for my site and i have a simple script:
[code]<?php

$con1 = mysql_connect("localhost","LOGIN", "PASSWORD");

$domain = GetHostByName($REMOTE_ADDR);
$browser = $_SERVER['HTTP_USER_AGENT'];
$page = $_SERVER['SCRIPT_NAME'];

mysql_select_db("stats", $con1);

$sql44="INSERT INTO `visitors` ( `IP` , `BROWSER` , `PAGE`, `TIME`)
VALUES ('$domain', '$browser', '$page', NOW() );";




if (!mysql_query($sql44,$con1)) { die('Error: ' . mysql_error()); }

?>
[/code]
of course for sanity i have this page called getinfo.php and use it as an include on different pages i want to track. So say on my index page i have <?php include "getinfo.php"; ?>

now here's the problem....

when i load the index page it inserts the data multiple times. It's not at all consistant with how many it will insert 1,2,3,4 up to 5. The TIME column is a TIMESTAMP in MySQL format and is also the primary index for the table. What's weird is it works fine if you only load getinfo.php by itself and not as an include. I have tried this include in both the head and body and produces the same result. Any Ideas would be very much appreciated!
Link to comment
Share on other sites

My gut feeling is that you have an include loop.  If you aren't already, try using include_once() instead of include().

Another idea is to print something out at the start of each of your files.  Then you can see in what order which file is run.  It basically gives you a trace of what was included where.  Alternatively you can put this data into a global array, and print it out later.
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.