rhock_95 Posted March 6, 2008 Share Posted March 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/ Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 if($ip == whatever you want){ carry out this action } Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484483 Share on other sites More sharing options...
rhock_95 Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks for the reply... can you elaborate a bit? "whatever you want" can this be "$array"? and $array=xxx.xxx.xxx.xx0 $array=xxx.xxx.xxx.xx1 $array=xxx.xxx.xxx.xx2 $array=xxx.xxx.xxx.xx3 ? Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484485 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 i;m not quite sure. try doing this $x = your array if($ip == $x){ blah } Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484502 Share on other sites More sharing options...
rhock_95 Posted March 6, 2008 Author Share Posted March 6, 2008 I can't get your original snippet to work if($ip == whatever you want){ carry out this action } if I use my own IP and tel it to close the file...it still logs the data... i.e., the "if" statement does nothing.. Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484520 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484535 Share on other sites More sharing options...
rhock_95 Posted March 6, 2008 Author Share Posted March 6, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484559 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 hahaha. sorry. The (hack) then talking about google got me kinda thinking... so anyways, i think you may be "over-logic-ing" all this. i'm fairly certain there are simple html tags to turn crawlers away. Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484567 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 hahaha. sorry. The (hack) then talking about google got me kinda thinking... so anyways, i think you may be "over-logic-ing" all this. i'm fairly certain there are simple html tags to turn crawlers away. Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484568 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 edit mistakes... up. Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484569 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 are you trying to get the log.txt file in the directory before logs? if so, turn this: $hFile = fopen( "./logs/log.txt", "a+" ); into this: $hFile = fopen( "../logs/log.txt", "a+" ); Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484571 Share on other sites More sharing options...
rhock_95 Posted March 6, 2008 Author Share Posted March 6, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-484848 Share on other sites More sharing options...
rhock_95 Posted March 6, 2008 Author Share Posted March 6, 2008 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...] Quote Link to comment https://forums.phpfreaks.com/topic/94616-help-with-if-statement-i-think/#findComment-485371 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.