How to include UNIX username and login IP address in php email script?

Hi,

I've created a php script to send email anytime a user logs into my linux server, I'm running SUSE 10.2 OS

I need a way to include in this email the user logging in and the IP address would be great as well.

I thought maybe adding parameters every time the script is called, something like sendmail.php $USER $IP
but i'm not sure if this is the right approach or how to implement it.

TIA
eDiasAsked:
Who is Participating?
 
sakuya_suConnect With a Mentor Commented:
a way of alerting on SSH, is to use the bashrc, add the line:

echo 'ALERT Shell Access (YourserverName) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" you@yourdomain.com

be sure to change the email and servername
0
 
sakuya_suCommented:
how are they loged in? through a web interface? ssh?
0
 
eDiasAuthor Commented:
these users are logging in via a SSH terminal!
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
Kiran Paul VJComputer EngineerCommented:

$ip=$_SERVER['REMOTE_ADDR'];

"sendmail.php?userip=".$ip;

if only registerd users can access your website, u can get the username from the database, otherwise its impossible.

kiranvj
0
 
Kiran Paul VJComputer EngineerCommented:
sorry i thought users are logging from website.
0
 
eDiasAuthor Commented:
sakuya_su,

Thanks, for your fast reply and great answer... I added your input to a .sh file and included this in /etc/profile from now on when ever any one logs into my system I'll get notified
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.