1

how do i check from within a php script, if a user is logged in? My current way is, to get the output of

w | grep <username>

and check, if there is output. It works, if a user is logged in via gdm, kdm or ssh or login on a tty. But what it doesn't get is, if an other user opened a terminal and run su <username>, this shell process is not reported, how do i get this?

1 Answer 1

2

Well, if userA uses su to become userB, then userB is still not logged in.

However, how about this:

ps -u <username>

Then you can check $? -eq 0 to see if any processes were found belonging to that user. However, if there are any long-running processes owned by that user, then it will still show them. If that's no good, you could check for their shell.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .