Apache logging PHP pages twice?
Posted: Mon Aug 22, 2005 7:09 am
Hi,
I am new to PHP but very familiar with databases. I have written a simple piece of code to log requests in a MySQL table when the index.php file is processed.
This is working fine except that the number of hits is always incremented by 2 not 1. It seems from looking at the Apache log that each PHP page is being requested twice.
Is this a known problem with Apache / PHP?
Note that if I debug this with Gubed this does not happen.
I am new to PHP but very familiar with databases. I have written a simple piece of code to log requests in a MySQL table when the index.php file is processed.
Code: Select all
<?php
require '../header.php' ;
$dbc = mysql_connect ($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db) or die('Cannot select database!') ;
$rem_addr = $_SERVER["REMOTE_ADDR"] ;
$ins = "INSERT INTO requests(conn_addr, hits, timestamp) VALUES ('$rem_addr' , 1, NOW())" ;
$upd = "UPDATE requests SET hits = hits + 1, timestamp = NOW() WHERE conn_addr = '$rem_addr'" ;
$result = mysql_query($ins) ;
if (!$result)
$result = mysql_query($upd) ;
?>
(the database connection is closed later).Is this a known problem with Apache / PHP?
Note that if I debug this with Gubed this does not happen.