h0mayun Posted September 1, 2011 Share Posted September 1, 2011 hi guys im trying to create a php mysql hit counter,it will counts hits on every page here is the code <?php function log_hit(){ $page = mysql_real_escape_string(basename($_SERVER[ 'SCRIPT_NAME' ])); //echo $page; $sql = "INSERT INTO `hits` ( `page_name`, `hits` ) VALUE ( '{$page}', 1) ON DUPLICATE KEY UPDATE `hits` = `hits` +1"; mysql_query($sql); } function fetch_stats(){ $result = mysql_query( 'SELECT `page_name`, `hits` FROM `hits` ' ); $stats = array(); while (($row = mysql_fetch_assoc($result)) !== false){ $stats[ ] = $row; } return $stats; } ?> so by adding log_hit(); function in pages it will record hits but im trying to restrict my ip address to be counted i mean i dont want to that mysql record hits from certain IP address,in this case my ip address so i added this codes $ip = getenv("REMOTE_ADDR") ; $myip = "127.0.0.1"; if ( $ip != $myip ){ //above code } it works good but when i open a page gives me an errorr Call to undefined function log_hit() and nothing loads how to ignore this error anf just force to loading page? Quote Link to comment https://forums.phpfreaks.com/topic/246216-i-need-help-with-if-else-function/ Share on other sites More sharing options...
noXstyle Posted September 1, 2011 Share Posted September 1, 2011 Have you included the actual function file to the page you are calling the function from? Quote Link to comment https://forums.phpfreaks.com/topic/246216-i-need-help-with-if-else-function/#findComment-1264500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.