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.
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?
?
?
?
?
?