How to implement the conclusion of users who are online? There is a registration system how to make a seat.
- php.su/articles/?cat=examples&page=039 I used this article to do everything as it says, but I still need to know how to make registered users write the name who is online, but the registration system I used is ruseller.com/lessons. php? rub = 37 & id = 506 Well, for example, I can bring all users from the database to the page, what should I do next - paloshmaxpro
- if you can do it then help - paloshmaxpro
- An example of what I need at the bottom of the testphp.ucoz.ru site, but down there, users also display me as it should be - paloshmaxpro
- Edited your answer, look, try - iproger
- and you watched the links that I sent - paloshmaxpro
1 answer
If you do not know the language, then you are on freelance. If you know, then I will bring an idea: make a table with online users in a database. And when a user visits the site, fill in his id and the time of his visit to it, and each time he visits a page, update the time of his visit. Further, on the online listing page, display all users from the created table, which, for example, has the last visit time less than 2 minutes ago. If more, then delete this entry. If something is not clear, ask.
Well, first, creating a table will look like this:
CREATE TABLEThe code did not check, there will be errors, write - we will debug it together. Now we need to make all pagesonline(idint (10) NOT NULL auto_increment,ipvarchar (20) NOT NULL default '0',iduservarchar (80) NOT NULL default '0',unixvarchar (60) NOT NULL default ', KEYid(id))
include 'online.php'; on_line ();But if you want to display a table of users online, then so:
on_line (true);Here is the code online.php:
------ File online.php
/ f-I counts users on the line; returns the number of users in formatted, i.e. to output the result you only need to register in right place type: echo on_line (); / function on_line ($ echousers = false) { $ host = "localhost"; // host where MySql database is located $ db_name = ""; // database name; as a rule coincides with the user name // (variable below), although I am categorically against the same // names, focusing on protection ... $ db_user = ""; // user allowed access to the database $ db_password = ""; // user password $ wine = 300; // online accuracy (seconds); time during which // user who came to the page, we consider to be // Online $ table_online = "online"; // table name // make global variable IP addresses available global $ REMOTE_ADDR; // connect to the MySQL server and select the desired database mysql_connect ($ host, $ db_user, $ db_password) or die (mysql_error ()); mysql_select_db ($ db_name) or die (mysql_error ());
// delete all those who have already spent $ wine seconds or who has the current IP $ sql_update = "DELETE FROM $ table_online WHERE
unix+ $ wine <" .time (). "ORip= '$ _SERVER [REMOTE_ADDR]'"; $ result_update = mysql_query ($ sql_update) or die (mysql_error ());// insert your post $ sql_insert = "INSERT INTO $ table_online (id, ip, iduser, unix) $ result_insert = mysql_query ($ sql_insert) or die (mysql_error ());
// consider unique online $ sql_sel = "SELECT
idFROM $ table_online"; $ result_sel = mysql_query ($ sql_sel) or die (mysql_error ());$ online_people = mysql_num_rows ($ result_sel); // number of On-Line users $ online_people = (string) $ online_people; // cast to string type // (this is necessary .. see further)
$ rain = strlen ($ online_people) - 1; // number of the last character in the number // on-line users
// formatting output (I did everything for you =) if ($ online_people [$ rain] == 2 || $ online_people [$ rain] == 3 || $ online_people [$ rain] == 4 || (strlen ($ online_people)! = 1 && $ online_people [strlen ($ online_people) -2]! = 1)) // $ line - variable that defines the output format $ line = "person"; else $ line = "person"; // return the result if ($ echousers == false) return "On <strong>". $ online_people. "</ strong> $ line"; else { echo "<table>"; while ($ row_sel = mysql_fetch_array ($ result_sel)) { $ res2 = mysql_query ("SELECT * FROM users WHERE pk_user = '$ row_sel [iduser]'"); $ row2 = mysql_fetch_array ($ res2); echo "<tr> <td>". $ row2 ['flname']. "</ td> </ tr>"; } echo "</ table>"; } }
- hmm and there is some kind of manual - paloshmaxpro
- I know the language but not too much: I am not yet a pro - paloshmaxpro
- php.net/manual/en/index.php Here is the official manual for php. But I think you need to watch it after learning a language. For example, there is a good book: Basics of PHP programming (Larry Ullman) - iproger
- Well yes. In principle, you can search for a lesson article on this topic. - iproger
- Do you have a samopisny script? ILI can CMS what? For example, wordpress or joomla? - iproger
Protected by a community spirit ♦ 6 May '18 at 20:45 .
Thank you for your interest in this issue. Since he collected a large number of low-quality and spam responses, which had to be deleted, now it’s necessary to have 10 reputation points on the site (the bonus for account association is not counted ).
Maybe you want to answer one of the unanswered questions ?