Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

"Who is online" script for Ajax chat (can be integrated universally)

#1
This is a very simple script that generates a list of users online in Ajax Chat, and it can be integrated with your website easily using an iframe. You can use notepad++ to paste this into a file named online.php, or you can alternatively download the attached file. You will need to manually configure the database connection settings (on line 2 of the script) but other than that it should work without any need for changes. It also puts the user's username in italics if [Away] is found in the username, which is designed to make it compatible with "AFK" command modifications. You can modify this as needed.

Code:
<?php
$con=mysqli_connect('DB_host','DB_user','DB_password','DB_name');


$sql = 'SELECT
userID,
userName
FROM
`ajax_chat_online`;';
$result = mysqli_query($con, $sql);
echo "Users Online: ";
$i=0;
while($row = mysqli_fetch_array($result))
{
$away_text = "[Away]"; // This will italicized usernames that have [Away] anywhere in the username. This can be modified as needed.
if (strrpos ($row['userName'], $away_text, -1)){
$string = str_replace("[Away]", "", $row['userName']);
echo "<i>".$string. "</i>";
}
else {
echo $row['userName'];
}
echo ", ";
$i++;
}
if ($i != 1) {
echo " <b>".$i." members online</b>";
}
else {
echo " <b>".$i." member online</b>";
}

mysqli_close($con);
?>
Important: : Make sure to use a program such as notepad++ to paste the contents of this file. Otherwise, extra space will be put at the beginning of the file that will make it unexecutable. You may also download the attached file.

I have set this up to be integrated on the index using an iframe at several websites. You can use something like this to integrate this script into any place on your forum or website. Modify this as needed.

Code:
<iframe style="display:inline;" src="http://example.com/chat/online.php" height="44px" marginheight="1px" frameborder="0" width="550px" scrolling="auto" seamless>Live Chat <a href="http://example.com/online.php">click here to see who is online. </a></iframe>


Attached Files
.php   online.php (Size: 741 bytes / Downloads: 435)

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Discord vs. Ajax Chat vs. IRC Darth-Apple 9 4,865 April 26th, 2020 at 6:30 PM
Last Post: Darth-Apple
  An improved Ajax Chat Darth-Apple 7 12,647 January 26th, 2014 at 8:23 PM
Last Post: Darth-Apple



Users browsing this thread: 1 Guest(s)

Dark/Light Theme Selector

Contact Us | Makestation | Return to Top | Lite (Archive) Mode | RSS Syndication 
Proudly powered by MyBB 1.8, © 2002-2024
Forum design by Makestation Team © 2013-2024