PHP who’s online

I have had alot of requests from people who wanted to know how to check if a user is online or not. So today I will show you how to simple display “online” next to the users name. And I will also show you how to display only the users online.
 

 
First we’re gonna check if the user is online.
Display the users currently online. Place this code anywhere that you would like the the online users to display. Use the $online variable to display the users currently online.
Place this on every page. This code will get the current users time and update it to the database.
Only show the users online.

Tagged with:

View all contributions by

Website:

Related Articles

Advertisement

Stay connected with us

Add us on Google+

Follow us on Facebook

Follow us on Twitter

Get updates via RSS

Get email updates

FEEDBACK17

  1. Alex_moyanah
    3

    Hi thanks very much for this tutorial – I really appreciate it and you are most helpful. However I have copied all the files and run them on my NetBeans compiler. It all works apart from the echoing of the status, the data is inserted into the databse and everything but no posts are displayed. Please help.

    Thanks

    1. Barrett Palmer
      6

      NO licence on it. It’s free to use. Just leave the comments on it to link back to Us.
      Thanks,
      Barrett

  2. David Wardy
    7

    I have put a basic social network site together it has login, register, profile, home page and a fair few other pages all is secure, design is up and it has a structure. It also has a basic profile image uploader and a basic status area within the profile.
    Wondering if you would like to work on it with me and work towards something, maybe pick up a few more coders along the way like FB did.
    I’m on a dedicated server and have a good Idea of where I’d like this project to go. If you would like to jump aboard please get in touch with me via facebook or email. amazeus@hotmail.co.uk.

    Cheers
    Dave

  3. David Wardy
    9

    Hey Barrett,

    I do believe something is wrong or missing from the status_update.php file. I don’t know if you have tested it on a database from home, but when you post a comment and refresh the page the comment dissapears in the web browser. But still continues to show the comment in the database.

    I’ve also added this into the script.

    $get_status=mysql_query(“SELECT * FROM status ORDER BY id DESC LIMIT 100;”)

    This is better for selecting the comments. Else it throws up a SQL SYNTAX error when trying to post.

    1. Barrett Palmer
      10

      I have tested it on a server and it works great! This script only inserts the status. To display all users statuses you will need to make a new file then select the status for that user.

      And the correct syntax is:
      $get_status=mysql_query(“SELECT * FROM status ORDER BY id DESC LIMIT 1″) or die (mysql_error());

      Not:
      $get_status=mysql_query(“SELECT * FROM status ORDER BY id DESC LIMIT 100;”)

      We only want to select 1 row not 100.

      1. sony
        11

        Hi Barrett,

        this looks really awesome, really amazing,

        I’m sorry guys but I’m a total beginner

        Could someone explain me how to create the database on mysql and add this into the files?

        I’m using wamp server but also dreamweaver

        thanks

        Sony

        UK

    1. Barrett Palmer
      15

      Your welcome! The code above will prepend to the load status out div. You should not have any problems. Can you give me a link to your site?

      1. akil
        16

        seems like i touched the div code. about my site, it not ready to hosting yet, maybe in 2weeks or more.. and how about the comment? and can you please publish about edit-in-place with ajax? it really helps me out. 

  4. Sokol
    17

    That’s what I’ve been looking for!! I am tired searching for Users who’s online, and now I found it I am so happy :):) Thank you Barret

    I have a small MySQL database only one table:users, for friends to login on one of my hobbypage.php

    Now what do I do on MySQL database table:users to display who’s online when they login on hobbypage.php?

    What I am trying to do is I am trying to create a onlinepage.php like your picture up there just to display users who’s online when they login on hobbypage.php, which at any time I want I go to onlinepage.php I can see who is currently online, friends that I have added on table:users.

    Please help me,

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">