Jump to content

help with "if" statement (I think)


rhock_95

Recommended Posts

Not being a coder (just a hack)...I think I need an if statement...?

 

I have a logging script that runs on a search form...the problem is Google and other searchbots load up the log file...

 

Can I use an if statement to match IP addresses against an array of IPs ?

and "if" the IP matches one in the array close the file? (write nothing) "else" it writes the data...?

 

here is the logging script:

<?php  
$hFile = fopen( "./logs/log.txt", "a+" ); 
fwrite( $hFile, "\n$city;$query;$category-"); 
fwrite($hFile,date("l, F jS Y - H:i:s-").($ip = $_SERVER['REMOTE_ADDR']));
fclose( $hFile ); 
?>

 

TIA

 

Link to comment
https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/
Share on other sites

i don't get what you are trying to do...

are you trying to hack into something?

 

trying to mess with google? I'll pass. They made a few BILLION dollars in profit last quarter... lets just say they've been spending an extra buck or two on prosecuting hackers.

 

 

 

Geeze...!

 

this is nothing but a flat file log script I have running on my own search form that searches my own database...but because I have Google Adsense ads running in the results pages... the spiders are constantly crawling the form and executing the log script...

 

all I am trying to do is stop the script from logging the data if an IP address matches the searchbot IP addresses...

to clarify...

 

I want the search engines crawling the page...I just don't want them executing the log file script...

 

I want to see what my users are searching for but the crawlers are constantly loading the log file so it is difficult to see whatr actual users are looking for...

 

My intention is to simply stop certain IP addresses from executing my logging script..

 

I thought I could do this with an "IF" statement but so far no joy...

I solved this problem with the following code:

 

$deny = array("111.111.111", "222.222.222", "333.333.333");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
   header("location: http://www.google.com/");
   exit();
}

 

if the IP=true the browser is redirected to Google.com

 

[could not find the "solved" link...]

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.