poster ip in mail notification to admin

Everything related to MBoard - PHP message board
Locked
DenisMcMahon
Posts: 1
Joined: Sat Aug 01, 2009 10:23 am

poster ip in mail notification to admin

Post by DenisMcMahon »

I modified the notify admin function as follows:

/* code starts here */
/* Notify admin */
if ($settings['notify'] == 1)
{
$poster_ip = $_SERVER['REMOTE_ADDR'];

$message = "Hello!

Someone at $poster_ip has just posted: $settings[mboard_url]/$newfile

Mboard Admin

";
mail($settings['admin_email'],'New forum post',$message);
}
/* code ends here */

Might be of interest to others.

I'm also wondering about writing to a log file whenever a post is made, date / time / ip / subject / file ....... so then ....

Ok, I added this after the above function:

/* code starts here */
/* log the post? */
if ($settings['LOG_POSTS'] == 1) {
$poster_ip = $_SERVER['REMOTE_ADDR'];
$logfile = $settings['LOG_FILE'];
$log_fp = @fopen($logfile,"a"); /* if the open fails, do so silently */
if ($log_fp) { /* open didn't fail */
fprintf($log_fp,"%s %s posted %s\n",date(DATE_RFC822),$poster_ip,$newfile);
fclose($log_fp);
}

else { /* open failed, Notify admin, needs "track_errors = On" in php.ini for $php_errormsg variable */

if ($settings['notify'] == 1)

{
$poster_ip = $_SERVER['REMOTE_ADDR'];

$message = "Hello!

I was unable to open the log file: $logfile
The error message was: $php_errormsg


Mboard Admin

";

mail($settings['admin_email'],'Failed to open logfile',$message);

}

}
}
/* code ends here */

and added 2 entries in settings.php:

/* code starts here */
/* Write a log file for new posts. 1 = YES, 0 = NO */
$settings['LOG_POSTS']=1;


/* absolute path to log file */
$settings['LOG_FILE']="/disks/hd2/www/board/posts.log";

/* code ends here */

Obviously make sure the script can create / append to the log - write permissions on file and dir

Denis
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Thanks for sharing, I'm sure others will find this useful.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Locked