auto update online user list when new userlogin

294 views Asked by At
<?php        
<div class="someclass">
    <ul class="someclass">
        foreach ($this->showonline as $key => $friend) {
        <li>
            $friend['avatar'];
            $friend['name'];
        </li>
        }

    </ul>
</div>
?>

exmple :-

  1. model.php
  2. class.php
  3. hook.php
  4. index.phtml

with model i get database information. with class im calculating online friend list as a array using array_intersect. and with hook i render to index.phtml. in phtml i use foreach loop and get the result to my online friendlist.

Here is my function im getting online user list with this. but if new user come to online i must refresh the page to see new online member. i want to make it auto update list. with ajax or something. can someone give me example how can i do that?

2

There are 2 answers

1
Ashique C M On BEST ANSWER

You may use setTimeout function, either to reload the page or to call ajax and update the page content. here is small idea.

setTimeout(function(){
// Do code here for reload/ajax here.
}, 3000);
0
Zz'Rot On

I believe the problem is more involved than merely front-end.

You will need the client to establish a socket with your server such that your server is able to constantly inform users of new online users. Otherwise, using a stay-alive connection with the server can also help, and use some jQuery to handle user list updates.