How to show number of user in online based on country wise ?


In this article I have explained about how to display available number of user in online based on his/here country. The user native country is stored in user table during registration and get result online status using status field in user table.

Description:
That is Possible to get number user online using status of that user. This website I have check the user is already login in the website or not. If not login then allow to login into the website and change his Status to "Y". If he click log out then we have update that user status "N".

How to update value "N" during browser close event?
We need to update database table value as "N" when user closed the browser I am using Global.asax file for update "N" value after session is expired.

How to calculate number of user online per country?
In this example site I have stored user details with country name. So when ever user login into the website I update status then show in the right side of the website number of available user per country. Like below code I count number of user


if (!Page.IsPostBack)
{
if (Session["uname"] == null || Session["uname"].ToString() == "")
{
Response.Redirect("ErrorPage.aspx");
}
sqlcon.Open();
sqlcmd = new SqlCommand("select distinct country from Login_Table", sqlcon);
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
sqlcon.Close();
if (dt.Rows.Count > 0)
{
sqlcon.Open();
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
sqlcmd1 = new SqlCommand("select count(*) from Login_Table where status='Y' and country='" + dt.Rows[i][0].ToString() + "'", sqlcon);
da1 = new SqlDataAdapter(sqlcmd1);
dt1.Clear();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
if (dt1.Rows[0][0].ToString() != "0")
{
Label1.Text += dt.Rows[i][0].ToString() + " " + dt1.Rows[0][0].ToString() + "
";
}
}
}
sqlcon.Close();
}
}

Source Code Detail:
Here with I have attached source code with Database and its details. Download it and try to login various user name, password from various browsers and check it number of user in online based on country.
Front End : ASP.NET
Code Behind : C#

Note: In this website folder I have created "READ_ME.txt" just read It default user name and password d for login.

Conclusion:
I hope my article help to show country based available online user.


Attachments

  • Show_Online_user (42950-12025-CountOnlineUser.rar)
  • Comments

    Author: Amit Vaish24 Jun 2011 Member Level: Bronze   Points : 1

    Hi,

    This is not the complete solution.
    You have provided only the basic things to be done.
    The challenging scenario is what about when user closes a browser.
    How do you update value to N when browser closed?
    ?
    ?
    ?
    ?
    ?

    Author: Ravindran25 Jun 2011 Member Level: Gold   Points : 1

    No Alok agw...i gave entire solution download my source code and try to close your browser i update "N" value using Globax.asax file Session end event.

    Author: Amit Vaish25 Jun 2011 Member Level: Bronze   Points : 1

    Hey brother,

    Thanks a lot to you.....yes you are right this is updating value on browser close after when session expires.
    But how can we prevent user to login again into the application.untill the previous session expires.

    Please right some words about it also.
    Thanks again....

    Author: Amit Vaish25 Jun 2011 Member Level: Bronze   Points : 1

    Hey brother,

    Thanks a lot to you.....yes you are right this is updating value on browser close after when session expires.
    But how can we prevent user to login again into the application.untill the previous session expires.

    Please right some words about it also.
    Thanks again....

    Author: Amit Vaish25 Jun 2011 Member Level: Bronze   Points : 1

    Hey brother,

    Thanks a lot to you.....yes you are right this is updating value on browser close after when session expires.
    But how can we prevent user to login again into the application.untill the previous session expires.

    Please right some words about it also.
    Thanks again....

    Author: Ravindran25 Jun 2011 Member Level: Gold   Points : 1

    No alok user never login again in to the website until previous session is expired if he/she try to login then message display "your previous session is not expired please try after some time".



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: