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