Run javascript function in php

Asked

Viewed 367 times

1

I’m building a chat system in php, and in the online client verification function that will be an ajax calling a php file from 30 to 30, and in this file there will be a foreach that will bring each user and do the checking, and need to do a function, that if it appears that the client is offline, change the html class in the attendant panel to offline, inside the foreach. That is, for every user that he sees that is offline he would already setting inside the foreach that the client is online or ofline by changing his class.

Would it be possible to run this JS function inside php? or in php to call a JS function?

  • Use this Ajax to return some kind of information (a flag) to detect that the user is off and then change the class.

  • is that this foreach would check every user that is being picked up on foreach and already set every user that were ofline, with its solution I would achieve, only that only 1 user and not all at once, correct me if I am wrong please, because I’m new to programming and php.

  • Let’s say I’m a user, and I’m on the page. From what I understand, this Ajax does not work "just for me", it is played in the background for the whole system, that’s it?

  • I have an ajax for clients (which would be your case) and another for attendants. in your site when you logged in there would be a javascript running that would save every 1 minute a json file with the date and time that was checked that you are online, and on the attendant’s side there would be a javascript that would use an ajax to check if this file exists and if it exists compares the difference of the current time and the time saved in your file, if the result exceeds 1 minute you are ofline, if you are online. that’s basically it.

1 answer

-1

Guys I managed to solve as follows, I did the checks of the users who were online in the php file, and after checking I put the id of the users online in an array and returned this array to the JS, in js I went through a for each id of the array marked as online. So I’m doing this requisition every 10 seconds. Thanks to those who helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.