<b>the first part of this script was obtained from a topic from this forum<br />i did not create this script i just added to it</b><br /><br />i am just looking for a way to make it write to a text file when the bot came and then display it on my Page<br /><br />any ideas<br /><br /><!-- Begin search engine bot Detection PHP --> <br /><!-- begin obtained from here --><br /><?php<br />if(eregi("googlebot",$HTTP_USER_AGENT))<br />{<br />if ($QUERY_STRING != "")<br />{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}<br />else<br />{$url = "http://".$SERVER_NAME.$PHP_SELF;}<br />$today = date("F j, Y, g:i a");<br />mail("[email protected]", "$HTTP_USER_AGENT has indexed your <!-- m --><a class="postlink" href="http://$SERVER_NAME">http://$SERVER_NAME</a><!-- m -->", "$today - $HTTP_USER_AGENT indexed $url");<br />}<br /><!-- End obtained from here --><br /><br /><br />$filename = "http://".$SERVER_NAME.botlog.txt;<br />$log = "$HTTP_USER_AGENT,$today\n";<br /><br />$log = fopen("$filename", "w+");<br />print "$HTTP_USER_AGENT crawed this site on $today";<br />(fclose($log)<br /><br />?> <---i get a syntax error here <br /><br /><!--end search engine bot Detection PHP --><br />this is hard but i will get it soon <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid="" border="0" alt="wink.gif" /><!--content-->
<!--coloro:blue--><span style="color:blue"><!--/coloro-->$filename = "http://".$SERVER_NAME.botlog.txt;<!--colorc--></span><!--/colorc--><br /><br />Change that line to something like this:<br /><br /><!--coloro:red--><span style="color:red"><!--/coloro-->$filename = "http://home/yourcpanelname/botlog.txt";<!--colorc--></span><!--/colorc--><br /><br />And change this line: <!--coloro:blue--><span style="color:blue"><!--/coloro-->(fclose($log)<!--colorc--></span><!--/colorc--><br /><br />To this: <!--coloro:red--><span style="color:red"><!--/coloro-->fclose($log);<!--colorc--></span><!--/colorc--><br /><br />I'm just learning PHP, you may have other errors.<!--content-->
Sorry TCH-Bruce but your modification generated this<br />Parse error: parse error, unexpected ';' in /home/cpanelname/public_html/index.php on line 338<!--content-->
You need to replace "cpanelname" with your user name on the server. And you don't want to write to your index.php file, you want to create the .txt file.<br /><br />And I did make a mistake. It should have been.<br /><br /><!--coloro:blue--><span style="color:blue"><!--/coloro-->$filename = "http://home/yourcpanelname/<b>public_html/</b>botlog.txt";<!--colorc--></span><!--/colorc--><!--content-->
yes i did i just replace it in here so no body would see it<br />and i added the public_html<br /><br />plus i thought it should be <br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br />since it is on the server<!--content-->
<!--QuoteBegin-mr_lucas+Oct 11 2004, 07:48 PM--><div class='quotetop'>QUOTE(mr_lucas @ Oct 11 2004, 07:48 PM)</div><div class='quotemain'><!--QuoteEBegin-->yes i did i just replace it in here so no body would see it<br />and i added the public_html<br /><br />plus i thought it should be <br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br />since it is on the server<!--QuoteEnd--></div><!--QuoteEEnd--><br />Hi mr_lucas,<br />Yes, the filename string you have there looks correct.<br /><br />The line:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->print "$HTTP_USER_AGENT crawed this site on $today";<!--c2--></div><!--ec2--><br /><br />doesn't write to the log file, which I'm assuming is what you want. Try this instead:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->fwrite($log, "$HTTP_USER_AGENT crawled this site on $today");<!--c2--></div><!--ec2--><br /><br />Also, this line can be removed:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$log = "$HTTP_USER_AGENT,$today\n";<!--c2--></div><!--ec2--><br /><br />It's not causing any problems for you, it's just not doing anything.<br /><br />The syntax error Bruce mentioned is the only one I could find, so the code should at least run. But then I am only half awake. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /> The error message you gave mentions line 338 in index.php, but we don't know what that line is. Could you copy/paste that line and a handful of lines before & after it? That would help.<br /><br />Good luck!<!--content-->
ok this is what this script is going to do, google pays a visit to site,<br />email is sent to me saying gogle came,<br />infomation is placed into the text file<br />Bot=google<br />date= 01/01/01<br /><br />then when a browser opens my page informaintion is displayed on page<br /><br />google was at this site on 01/01/01<!--content-->
Two additional issues, now that I'm fully awake. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /> <br /><br />First, the code to write to the log file is always executed, whether the page is requested by Googlebot or not. You want to move the rest of the code into the <b>if (eregi("googlebot",$HTTP_USER_AGENT))</b> block.<br /><br />Also, when you open the log file to write to it, you're wiping out the existing contents, which means you'll only ever have one entry in the log file at a time. This is probably not what you want, so open the file in append mode ("a") instead.<br /><br />With that and the other suggested changes, the script should do what you want. Are you still having problems with all these changes implemented? Try the following code:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />if(eregi("googlebot",$HTTP_USER_AGENT))<br />{<br />if ($QUERY_STRING != "")<br />{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}<br />else<br />{$url = "http://".$SERVER_NAME.$PHP_SELF;}<br />$today = date("F j, Y, g:i a");<br />mail("[email protected]", "$HTTP_USER_AGENT has indexed your http://$SERVER_NAME", "$today - $HTTP_USER_AGENT indexed $url");<br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br /><br />$log = fopen($filename, "a");<br />fwrite($log, "$HTTP_USER_AGENT crawled this site on $today\n");<br />fclose($log);<br />}<br />?><!--c2--></div><!--ec2--><!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec--><?php<br />if(eregi("googlebot",$HTTP_USER_AGENT))<br />{<br />if ($QUERY_STRING != "")<br />{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}<br />else<br />{$url = "http://".$SERVER_NAME.$PHP_SELF;}<br />$today = date("F j, Y, g:i a");<br />mail("[email protected]", "$HTTP_USER_AGENT has indexed your <!-- m --><a class="postlink" href="http://$SERVER_NAME">http://$SERVER_NAME</a><!-- m -->", "$today - $HTTP_USER_AGENT indexed $url");<br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br /><br />$log = fopen($filename, "a");<br />fwrite($log, "$HTTP_USER_AGENT crawled this site on $today\n");<br />fclose($log);<br />}<br />?><!--QuoteEnd--></div><!--QuoteEEnd--><br />ok the above script as been added to my site now just sit back and wait for google to come to the site i have notice it comes about every 3 to 4 days somtimes 5 days<!--content-->
<!--coloro:blue--><span style="color:blue"><!--/coloro-->$filename = "http://".$SERVER_NAME.botlog.txt;<!--colorc--></span><!--/colorc--><br /><br />Change that line to something like this:<br /><br /><!--coloro:red--><span style="color:red"><!--/coloro-->$filename = "http://home/yourcpanelname/botlog.txt";<!--colorc--></span><!--/colorc--><br /><br />And change this line: <!--coloro:blue--><span style="color:blue"><!--/coloro-->(fclose($log)<!--colorc--></span><!--/colorc--><br /><br />To this: <!--coloro:red--><span style="color:red"><!--/coloro-->fclose($log);<!--colorc--></span><!--/colorc--><br /><br />I'm just learning PHP, you may have other errors.<!--content-->
Sorry TCH-Bruce but your modification generated this<br />Parse error: parse error, unexpected ';' in /home/cpanelname/public_html/index.php on line 338<!--content-->
You need to replace "cpanelname" with your user name on the server. And you don't want to write to your index.php file, you want to create the .txt file.<br /><br />And I did make a mistake. It should have been.<br /><br /><!--coloro:blue--><span style="color:blue"><!--/coloro-->$filename = "http://home/yourcpanelname/<b>public_html/</b>botlog.txt";<!--colorc--></span><!--/colorc--><!--content-->
yes i did i just replace it in here so no body would see it<br />and i added the public_html<br /><br />plus i thought it should be <br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br />since it is on the server<!--content-->
<!--QuoteBegin-mr_lucas+Oct 11 2004, 07:48 PM--><div class='quotetop'>QUOTE(mr_lucas @ Oct 11 2004, 07:48 PM)</div><div class='quotemain'><!--QuoteEBegin-->yes i did i just replace it in here so no body would see it<br />and i added the public_html<br /><br />plus i thought it should be <br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br />since it is on the server<!--QuoteEnd--></div><!--QuoteEEnd--><br />Hi mr_lucas,<br />Yes, the filename string you have there looks correct.<br /><br />The line:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->print "$HTTP_USER_AGENT crawed this site on $today";<!--c2--></div><!--ec2--><br /><br />doesn't write to the log file, which I'm assuming is what you want. Try this instead:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->fwrite($log, "$HTTP_USER_AGENT crawled this site on $today");<!--c2--></div><!--ec2--><br /><br />Also, this line can be removed:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$log = "$HTTP_USER_AGENT,$today\n";<!--c2--></div><!--ec2--><br /><br />It's not causing any problems for you, it's just not doing anything.<br /><br />The syntax error Bruce mentioned is the only one I could find, so the code should at least run. But then I am only half awake. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /> The error message you gave mentions line 338 in index.php, but we don't know what that line is. Could you copy/paste that line and a handful of lines before & after it? That would help.<br /><br />Good luck!<!--content-->
ok this is what this script is going to do, google pays a visit to site,<br />email is sent to me saying gogle came,<br />infomation is placed into the text file<br />Bot=google<br />date= 01/01/01<br /><br />then when a browser opens my page informaintion is displayed on page<br /><br />google was at this site on 01/01/01<!--content-->
Two additional issues, now that I'm fully awake. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /> <br /><br />First, the code to write to the log file is always executed, whether the page is requested by Googlebot or not. You want to move the rest of the code into the <b>if (eregi("googlebot",$HTTP_USER_AGENT))</b> block.<br /><br />Also, when you open the log file to write to it, you're wiping out the existing contents, which means you'll only ever have one entry in the log file at a time. This is probably not what you want, so open the file in append mode ("a") instead.<br /><br />With that and the other suggested changes, the script should do what you want. Are you still having problems with all these changes implemented? Try the following code:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />if(eregi("googlebot",$HTTP_USER_AGENT))<br />{<br />if ($QUERY_STRING != "")<br />{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}<br />else<br />{$url = "http://".$SERVER_NAME.$PHP_SELF;}<br />$today = date("F j, Y, g:i a");<br />mail("[email protected]", "$HTTP_USER_AGENT has indexed your http://$SERVER_NAME", "$today - $HTTP_USER_AGENT indexed $url");<br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br /><br />$log = fopen($filename, "a");<br />fwrite($log, "$HTTP_USER_AGENT crawled this site on $today\n");<br />fclose($log);<br />}<br />?><!--c2--></div><!--ec2--><!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec--><?php<br />if(eregi("googlebot",$HTTP_USER_AGENT))<br />{<br />if ($QUERY_STRING != "")<br />{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}<br />else<br />{$url = "http://".$SERVER_NAME.$PHP_SELF;}<br />$today = date("F j, Y, g:i a");<br />mail("[email protected]", "$HTTP_USER_AGENT has indexed your <!-- m --><a class="postlink" href="http://$SERVER_NAME">http://$SERVER_NAME</a><!-- m -->", "$today - $HTTP_USER_AGENT indexed $url");<br /><br />$filename = "/home/yourcpanelname/public_html/botlog.txt"; <br /><br />$log = fopen($filename, "a");<br />fwrite($log, "$HTTP_USER_AGENT crawled this site on $today\n");<br />fclose($log);<br />}<br />?><!--QuoteEnd--></div><!--QuoteEEnd--><br />ok the above script as been added to my site now just sit back and wait for google to come to the site i have notice it comes about every 3 to 4 days somtimes 5 days<!--content-->