Jump to content

Reading & editing text files


esoteric

Recommended Posts

Hi guys, im logging activity on my site to text files using;

 

date_default_timezone_set('GMT');
$LogFileLocation = "xxxxxxxx.log";
$fh = fopen($_SERVER['DOCUMENT_ROOT'].$LogFileLocation,'at');
fwrite($fh,date('d.M.Y H:i:s')."\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_URI']."\n");
fclose($fh);

 

This is write something like;

[date]  [time]   [ip address] [folder accessed]

 

I then post it like;

<?
$fn = "xxxxxxxxxx.log";
print htmlspecialchars(implode("",file($fn)));
?> 

 

That works fine but what i want to be able to do is read/edit the text files, so the main things i need to add is;

 

The ability to clear the log (using password for confirmation) not sure how to go about this because i don't know how to edit the text file

<input name="password" type="text">

<input type="submit" value="Clear Log?">

 

I also need a script to read the log and alert me an ip address that isn't mine is found, maybe something like

if (an ip that isn't mine == yes)

echo "an unknown ip accessed something"

 

Also lets say i have a script that checks if a name exists, how can i use a text file containing a list of names to be read by a script

if (name exists in text file)

echo "name exists"

else

echo "name doesn't exist"

 

 

All these questions are similar in the fact i need to understand how to open and read text files for specific entries, hope you understand, thanks for any help.

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.