Forum Moderators: coopster

Message Too Old, No Replies

Use php to add content to a .txt file?

Want to make a .txt Googlebot log using php.

         

Jesse_Smith

5:41 am on Feb 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it possible to use a php script to put content in a .txt file? This script E-mails you the Googlebot info and I would like to turn it into making a .txt log file if it's possible.

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("you@youremail.com", "Googlebot detected on [$SERVER_NAME",...] "$today - Google crawled $url");
}

hakre

8:59 am on Feb 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi Jesse_Smith,

you can use php for shure for this. the commands needed are called fopen(), fwrite() and fclose(). you can even create a log while appending (the 'a' or 'a+' option in fopen) to that file. checkout the phpdocs, they come even with examples about this. the chapter is called 'file system functions'.

c3oc3o

11:54 am on Feb 22, 2003 (gmt 0)

10+ Year Member



Replace...
mail("you@youremail.com", "Googlebot detected on [$SERVER_NAME",...] "$today - Google crawled $url");
...with...
$logfile = @fopen('googlebot.txt', 'a');
@fputs($logfile, "$today - Google crawled $url \n");
@fclose($logfile);

Put an empty file called googlebot.txt in the directory and make sure it's writable ('CHMOD 666' should do the trick).

The @s before the functions surpress error messages, so you don't serve Googlebot PHP errors in case anything goes wrong.