Re: User listing..
| From: | stephan dot schoell at chhos dot mail dot abb dot com | Date: | Thu, 20 Jul 2000 14:26:55 +0000 |
| Subject: | Re: User listing.. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7423@lists.php.net to get a copy of this message | ||
Oyvind,
You definitely have to loop through the elements of the array $usr (be it a
string before or not), if you would like to list _all_ the users. The code
snippet below lists just one or no user... Please refer to my mail earlier this
afternoon.
-Steff
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net