Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
Nukeum66
Life Cycles Becoming CPU Cycles



Joined: Jul 30, 2003
Posts: 551
Location: Neurotic, State, USA

PostPosted: Sun Dec 14, 2003 1:27 am Reply with quote

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 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sun Dec 14, 2003 9:39 am Reply with quote

What is $iprn?
Try this code. I spruced it up a little Smile (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);
 
View user's profile Send private message
Nukeum66







PostPosted: Sun Dec 14, 2003 1:58 pm Reply with quote

Quote:
What is $iprn?


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 Laughing

But I think I may use your spruced up version anyway!

Thanks Wink
 
Nukeum66







PostPosted: Sun Dec 14, 2003 11:07 pm Reply with quote

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







PostPosted: Sun Dec 14, 2003 11:48 pm Reply with quote

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







PostPosted: Mon Dec 15, 2003 4:37 am Reply with quote

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







PostPosted: Mon Dec 15, 2003 5:32 am Reply with quote

Did you try
if (fwrite($fp, $iprn)) PRINT("Your Ip was logged.....$ip");
 
Nukeum66







PostPosted: Mon Dec 15, 2003 6:26 am Reply with quote

Well, tried it, no dice. Smile

The way I have it seems to be the only way it works.
 
Nukeum66







PostPosted: Mon Dec 15, 2003 6:32 am Reply with quote

Ok this works
Code:
if(fwrite($fp, "$ip,"))PRINT("<b>Your IP has been logged.....$ip</b>");
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©