Author |
Message |
Nukeum66
Life Cycles Becoming CPU Cycles

Joined: Jul 30, 2003
Posts: 551
Location: Neurotic, State, USA
|
Posted:
Sun Dec 14, 2003 1:27 am |
|
Ok, I have created a page that a ban user is redirected to when they try to access the site. Now, what I want to do is log their ip from this page by writing to a .txt .
This is what I have so far and it works as far as telling them the IP has been log as well as showing the IP, but I can't get the script to write to the .txt.
Code:$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$iprn");
flock($fp, 3);
fclose($fp);
PRINT("Your Ip was logged.....$ip");
|
I CHMODED .txt to 777 |
_________________ Scott Johnson MIS Ubuntu/Linux 11.10 |
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Sun Dec 14, 2003 9:39 am |
|
What is $iprn?
Try this code. I spruced it up a little (I haven't tested it though)Code:
$to = 'YOUR_EMAIL_ADDRESS';
$subject = 'Logging Failure Notice';
$msg = 'System was unable to write to the banned log file';
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = @fopen("$log_file", "a");
if (!$fp) @mail($to, $subject, "$msg","From: $admin_email_address");
@flock($fp,2);
if (@fwrite($fp, $iprn)) PRINT("Your Ip was logged.....$ip");
else @mail($to, $subject, "$msg","From: $admin_email_address");
@flock($fp, 3);
@fclose($fp);
|
|
|
|
|
 |
Nukeum66

|
Posted:
Sun Dec 14, 2003 1:58 pm |
|
LOL! You know what that was? It was the reason the script would not write to the text file! LOL! I used this code for something else and I forgot to change it . It should have been just $ip
But I think I may use your spruced up version anyway!
Thanks  |
|
|
|
 |
Nukeum66

|
Posted:
Sun Dec 14, 2003 11:07 pm |
|
Well I had to change a few things in your code, but I have it working nicely now. I'm not a script writer, so if you see anything wrong with the way I have change it please tell me.
Working functions are:
Tells the visitor their ip has been logged & shows it to them.
Writes to the .txt or .csv file.
Sends email with the IP within the message.
Code:
$to = 'YOUR_EMAIL_ADDRESS';
$subject = 'Logging Failure Notice';
$msg = 'System was unable to write to the banned log file';
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = @fopen("$log_file", "a");
if (!$fp) @mail($to, $subject, "$msg, $ip","From: $admin_email_address");
@flock($fp,2);
if(@fwrite($fp, "$ip, "));
PRINT("<b>Your IP has been logged.....$ip</b>");
@mail($to, $subject, "$msg, $ip","From: $admin_email_address");
@flock($fp, 3);
@fclose($fp);
|
I changed this because I was getting parse errors
Code:else @mail($to, $subject, "$msg","From: $admin_email_address");
|
|
|
|
|
 |
Raven

|
Posted:
Sun Dec 14, 2003 11:48 pm |
|
if(@fwrite($fp, "$ip, "));
That line no longer makes any sense nor serves any purpose now. If anything, just make it @fwrite($fp, "$ip, "); |
|
|
|
 |
Nukeum66

|
Posted:
Mon Dec 15, 2003 4:37 am |
|
Ok if I change that line in any way the script stops writing to the log file. The only way I can change it and it will work, is to change it to Code:if(@fputs($fp, "$ip, "));
| [/code] |
|
|
|
 |
Raven

|
Posted:
Mon Dec 15, 2003 5:32 am |
|
Did you try
if (fwrite($fp, $iprn)) PRINT("Your Ip was logged.....$ip"); |
|
|
|
 |
Nukeum66

|
Posted:
Mon Dec 15, 2003 6:26 am |
|
Well, tried it, no dice.
The way I have it seems to be the only way it works. |
|
|
|
 |
Nukeum66

|
Posted:
Mon Dec 15, 2003 6:32 am |
|
Ok this works
Code:if(fwrite($fp, "$ip,"))PRINT("<b>Your IP has been logged.....$ip</b>");
|
|
|
|
|
 |
|