PHP Web Host - Quality Web Hosting For All PHP Applications Clan Themes! We make clans look good!!
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
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 Back to top

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


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

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

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 Visit poster's website AIM Address Yahoo Messenger
Nukeum66
Life Cycles Becoming CPU Cycles


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

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

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
View user's profile Send private message Visit poster's website
Nukeum66
Life Cycles Becoming CPU Cycles


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

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

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


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

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

if(@fwrite($fp, "$ip, "));

That line no longer makes any sense nor serves any purpose now. If anything, just make it @fwrite($fp, "$ip, ");
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Nukeum66
Life Cycles Becoming CPU Cycles


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

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

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


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

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

Did you try
if (fwrite($fp, $iprn)) PRINT("Your Ip was logged.....$ip");
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Nukeum66
Life Cycles Becoming CPU Cycles


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

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

Well, tried it, no dice. Smile

The way I have it seems to be the only way it works.
View user's profile Send private message Visit poster's website
Nukeum66
Life Cycles Becoming CPU Cycles


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

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

Ok this works
Code:
if(fwrite($fp, "$ip,"))PRINT("<b>Your IP has been logged.....$ip</b>");
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum