Jump to content

i need help with if else function


h0mayun

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/246216-i-need-help-with-if-else-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.