I have a counter buried in a site script for hosting images. I call the counter with:
global $cntpage;
include ( ‘counter/counter.php’);
addinfo($cntpage);
******And the counter is:
<?php include ('counter/counter_config.php'); function addinfo($cntpage) global $cntlocalhost, $cntdbuser, $cntdbpass, $cntdbname, $cntdbtablehits,$cntdbtableinfo,$cntmaxrows,$cntpage; $link = mysql_connect($cntlocalhost, $cntdbuser, $cntdbpass); if (!$link) { die('Could not connect: ' . mysql_error()); // remove ? } $cntdbselect=mysql_select_db($cntdbname); if (!$cntdbselect) { die ("Can't use database $cntdbname! : " . mysql_error()); // remove ? } if(mysql_num_rows(mysql_query("SELECT page FROM $cntdbtablehits WHERE page = '$cntpage'"))) { //A counter for this page already exsists. Now we have to update it. $updatecounter = mysql_query("UPDATE $cntdbtablehits SET count = count+1 WHERE page = '$cntpage'"); if (!$updatecounter) { die ("Can't update the counter : " . mysql_error()); // remove ? } } else { // This page did not exsist in the counter database. A new counter must be created for this page. $insert = mysql_query("INSERT INTO $cntdbtablehits (page, count)VALUES ('$cntpage', '1')"); if (!$insert) { die ("Can\'t insert into $cntdbtablehits : " . mysql_error()); // remove ? } } $ip= $_SERVER["REMOTE_ADDR"]; $agent =$_SERVER["HTTP_USER_AGENT"]; $datetime =date("Y/m/d") . ' ' . date('H:i:s') ; if(!mysql_num_rows(mysql_query("SELECT ip_address FROM info WHERE ip_address = '$ip'"))) // check if the IP is in database { // if not , add it. $adddata = mysql_query("INSERT INTO $cntdbtableinfo (ip_address, user_agent, datetime) VALUES('$ip' , '$agent','$datetime' ) ") ; if (!$adddata) { die('Could not add IP : ' . mysql_error()); // remove ? } } result = mysql_query("SELECT * FROM $cntdbtableinfo", $link); $num_rows = mysql_num_rows($result); $to_delete = $num_rows- $cntmaxrows; if($to_delete > 0) { for ($i = 1; $i <= $to_delete; $i++) { $delete = mysql_query("DELETE FROM $cntdbtableinfo ORDER BY id LIMIT 1") ; if (!$delete) { die('Could not delete : ' . mysql_error()); // remove ? } } } // mysql_close($link); } ?>But for some reason, it will NOT post anything to the $cntpage spot. no matter what I do. Any ideas?