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

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.