Jump to content

Recommended Posts

Posted

the first part of this script was obtained from a topic from this forum

i did not create this script i just added to it

 

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

 

any ideas

 

<!-- Begin search engine bot Detection PHP -->

<!-- begin obtained from here -->

<?php

if(eregi("googlebot",$HTTP_USER_AGENT))

{

if ($QUERY_STRING != "")

{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}

else

{$url = "http://".$SERVER_NAME.$PHP_SELF;}

$today = date("F j, Y, g:i a");

mail("someone@somewhere.puga", "$HTTP_USER_AGENT has indexed your http://$SERVER_NAME", "$today - $HTTP_USER_AGENT indexed $url");

}

<!-- End obtained from here -->

 

 

$filename = "http://".$SERVER_NAME.botlog.txt;

$log = "$HTTP_USER_AGENT,$today\n";

 

$log = fopen("$filename", "w+");

print "$HTTP_USER_AGENT crawed this site on $today";

(fclose($log)

 

?> <---i get a syntax error here

 

<!--end search engine bot Detection PHP -->

this is hard but i will get it soon :lol:

Posted (edited)

$filename = "http://".$SERVER_NAME.botlog.txt;

 

Change that line to something like this:

 

$filename = "http://home/yourcpanelname/botlog.txt";

 

And change this line: (fclose($log)

 

To this: fclose($log);

 

I'm just learning PHP, you may have other errors.

Edited by TCH-Bruce
Posted

Sorry TCH-Bruce but your modification generated this

Parse error: parse error, unexpected ';' in /home/cpanelname/public_html/index.php on line 338

Posted (edited)

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.

 

And I did make a mistake. It should have been.

 

$filename = "http://home/yourcpanelname/public_html/botlog.txt";

Edited by TCH-Bruce
Posted

yes i did i just replace it in here so no body would see it

and i added the public_html

 

plus i thought it should be

 

$filename = "/home/yourcpanelname/public_html/botlog.txt";

since it is on the server

Posted
yes i did i just replace it in here so no body would see it

and i added the public_html

 

plus i thought it should be

 

$filename = "/home/yourcpanelname/public_html/botlog.txt";

since it is on the server

Hi mr_lucas,

Yes, the filename string you have there looks correct.

 

The line:

>print "$HTTP_USER_AGENT crawed this site on $today";

 

doesn't write to the log file, which I'm assuming is what you want. Try this instead:

 

>fwrite($log, "$HTTP_USER_AGENT crawled this site on $today");

 

Also, this line can be removed:

>$log = "$HTTP_USER_AGENT,$today\n";

 

It's not causing any problems for you, it's just not doing anything.

 

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

 

Good luck!

Posted

ok this is what this script is going to do, google pays a visit to site,

email is sent to me saying gogle came,

infomation is placed into the text file

Bot=google

date= 01/01/01

 

then when a browser opens my page informaintion is displayed on page

 

google was at this site on 01/01/01

Posted

Two additional issues, now that I'm fully awake. <_<

 

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 if (eregi("googlebot",$HTTP_USER_AGENT)) block.

 

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.

 

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:

 

><?php
if(eregi("googlebot",$HTTP_USER_AGENT))
{
if ($QUERY_STRING != "")
{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}
else
{$url = "http://".$SERVER_NAME.$PHP_SELF;}
$today = date("F j, Y, g:i a");
mail("someone@somewhere.puga", "$HTTP_USER_AGENT has indexed your http://$SERVER_NAME", "$today - $HTTP_USER_AGENT indexed $url");

$filename = "/home/yourcpanelname/public_html/botlog.txt"; 

$log = fopen($filename, "a");
fwrite($log, "$HTTP_USER_AGENT crawled this site on $today\n");
fclose($log);
}
?>

Posted
<?php

if(eregi("googlebot",$HTTP_USER_AGENT))

{

if ($QUERY_STRING != "")

{$url = "http://".$SERVER_NAME.$PHP_SELF.'?'.$QUERY_STRING;}

else

{$url = "http://".$SERVER_NAME.$PHP_SELF;}

$today = date("F j, Y, g:i a");

mail("someone@somewhere.puga", "$HTTP_USER_AGENT has indexed your http://$SERVER_NAME", "$today - $HTTP_USER_AGENT indexed $url");

 

$filename = "/home/yourcpanelname/public_html/botlog.txt";

 

$log = fopen($filename, "a");

fwrite($log, "$HTTP_USER_AGENT crawled this site on $today\n");

fclose($log);

}

?>

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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