Re: User listing..

From: Date: Thu, 20 Jul 2000 13:25:46 +0000
Subject: Re: User listing..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-7411@lists.php.net to get a copy of this message
Daniel Lundberg, > Hey there. > I have a small problem here, wonder if someone have a simple solution for > it. I've made a function that does a 'exec("users", $array);' to > display > the users that are logged in, on a site. So the array can contain none, > one or up to 5-6 objects. > I then want to look in the array and see what's in there, echo it to the > page and make a link to each users homepage when they are logged in. > What I've accomplished so far: > > <? > function dispUsr() { > exec("users", $usr); > if (in_array("ben", $usr)) { > echo "<a > href='http://www.somesite.org'>Ben</a>"; > } elseif (in_array("dover", $usr)) { > echo "<a > href='http://www.blah.net'>Dover</a>"; > } > ..... > } else { > echo "none"; > } > } > ?> > > And further down, a 'User(s) logged in: <? dispUsr(); ?>' tag. > This works fine, as long as more than one is not logged in. Then it fails. > I haven't found any example on how this could be made, but maybe with > some help by array_slice/sizeof? Firstly, the 'users' command at my box returns a string and not different lines. This means that $usr in your function should not be an array but a string. So perhaps something like this would work better: <?php function dispUsr() { exec("users", $usr); $usr = explode(" ", $usr); if (in_array("ben", $usr)) { echo "<a href='http://www.somesite.org'>Ben</a>"; } else if (in_array("dover", $usr)) { echo "<a href='http://www.blah.net'>Dover</a>"; } else { echo "none"; } } ?> -- Øyvind Grønnesby "Wow, I had knowledge!" --Buffy

« previous php.general (#7411) next »