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


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.

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`"

be sure to change the email and servername
how are they loged in? through a web interface? ssh?
eDiasAuthor Commented:
these users are logging in via a SSH terminal!
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:



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

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

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
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.