Jump to content

Incoming hits script help


netstormx

Recommended Posts

Right now in a script I have the script wont log my domain hits coming in with this

 

if(!empty($ref_domain) && preg_match("/" . str_replace(".", "\.", JARL_DOMAIN) . "/", $ref_domain)==0) {

 

I want to also block search engines due to server load. What would be the best way to do this adding it to this code?

 

Link to comment
Share on other sites

Sorry, I wrote that quick. What the script does is logs the domain thats incoming and puts it into the database. I want to keep tracking those sites, but dont want to track the incoming hits from the search engines.

 

The code I provided makes sure not to log hits from my domain, and I would like to modify that code to also say if "google.com" or "bing.com" etc. then ref_domain==0 as well. That way when it hits the code after this one it wont send any data to the database based on the domain==0 code.

Link to comment
Share on other sites

$domain = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if (!preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/', $domain)) {
    if (!preg_match('/(google|bing|mydomain)/', $domain)) {
        // tracking..
    }
}

 

if (!preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/', $domain))

 

Makes sure the returned address is not an ip-address but a domain name (making it safe to use in a visitor environment)

 

if (!preg_match('/(google|bing|mydomain)/', $domain))

 

Makes sure the domain name is not google, bing or our own domain name

 

// tracking..

 

This is where your logic will reside: add it to a database, ..

 

P.S. I'm not sure how long gethostbyaddr() takes to resolve an ip to domain name otherwise you may want to store the ip address along with the domain name of popular search engines for example: 74.125.127.100=google.com (http://74.125.127.100).

Link to comment
Share on other sites

Still having problems with this. Heres the full code of the php file.

 

I just want one line of code to not insert the google/bing/etc into the db, and not hit it since its taking up so many resources. I've tried everything.

 

 


if(basename($_SERVER["SCRIPT_FILENAME"])=="log.php") { exit; }

include_once(dirname(__FILE__) . '/config.php');

include_once(dirname(__FILE__) . '/jarl_db.php');

$jarl_db = new jarl_db();



// Obtain referring address

$ref_address = $_SERVER["HTTP_REFERER"];



// Determine referring domain

preg_match("/^https?:\/\/(www\.)?([a-zA-Z0-9\.\-_]+)/", $ref_address, $ref_domain);

$ref_domain = strtolower($ref_domain[2]);

$wc = preg_match("/^([a-zA-Z0-9\-]+)\.(([a-z]{2,3})\.([a-z]{2,3}))?([a-z]{2,3})?(\*)?/", $ref_domain, $ext);

$wildcard = $ext[1];



// Only log hits from foreign referer

if(!empty($ref_domain) && preg_match("/" . str_replace(".", "\.", JARL_DOMAIN) . "/", $ref_domain)==0) {

// Obtain IPs

preg_match("/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $_SERVER["HTTP_X_FORWARDED_FOR"], $fip);

preg_match("/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $_SERVER["HTTP_CLIENT_IP"], $cip);

preg_match("/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $_SERVER["REMOTE_ADDR"], $ip);



// Clean them up to prevent SQL injection

$ref_address = $jarl_db->clean($ref_address);

$ref_domain = $jarl_db->clean($ref_domain);

$fip = $jarl_db->clean($fip[1]);

$cip = $jarl_db->clean($cip[1]);

$ip = $jarl_db->clean($ip[1]);



// Check for most recent hit and determine whether this new hit will count

$ltime = $jarl_db->result("SELECT time FROM " . JARL_PREFIX . "in WHERE ref_domain='$ref_domain' AND ip='$ip' AND fip='$fip' AND cip='$cip' ORDER BY id DESC LIMIT 1");

if(!empty($ltime)) {

	$ctime = time();

	if(JARL_T_CONSTRAINT>($ctime-$ltime)/60) {

		if(JARL_T_PREVDAY) {

			$lday=floor($ltime/86400);

			$cday=floor($ctime/86400);

			$valid_hit = ($lday!=$cday) ? true : false;

		} else {

			$valid_hit = false;

		}

	} else {

		$valid_hit = true;

	}

} else {

	$valid_hit = true;

}



// Hit it up

if($valid_hit) {

	$geoip_data = $jarl_db->fetchrow("SELECT country,name FROM " . JARL_PREFIX . "ip WHERE MBRCONTAINS(ip_poly, POINTFROMWKB(POINT(INET_ATON('$ip'), 0)))");

	$jarl_db->query("INSERT INTO " . JARL_PREFIX . "in (id, fip, cip, ip, co, coname, ref_address, ref_domain, wildcard, time) VALUES ('', '$fip', '$cip', '$ip', '" . $geoip_data["country"] . "', '" . $geoip_data["name"] . "', '$ref_address', '$ref_domain', '$wildcard', " . time() . ")");

}

}

$jarl_db->kill();

?>

 

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.