A MySQL-based mini-chat to put as a block on your pages.
By : greggory
<?php
// Contains db constants
require "cst.inc";
/*
CREATE TABLE MINICHAT (
NB tinyint(4) NOT NULL auto_increment,
LOGIN varchar(20) NOT NULL default '',
MESSAGE varchar(255) NOT NULL default '',
ITSTIME varchar(10) NOT NULL default '',
) TYPE=MyISAM;
*/
// Number of messages to print
define( "_NB_MSGS_", 10 );
// Connect
mysql_connect( $db_hostname, $db_username, $db_password );
mysql_selectdb( $db_database );
// Add message into minichat
function addMessage( $login, $message ) {
@setcookie( "minichatlogin", strip_tags( $login ) );
$login = $_COOKIE['minichatlogin'] ? $_COOKIE['minichatlogin'] :
mysql_escape_string( strip_tags( $login ) );
$message = mysql_escape_string( strip_tags( $message, '<a><b><i><u>') );
mysql_query( "INSERT INTO MINICHAT ( NB, ITSTIME, LOGIN, MESSAGE ) VALUES ( "
._NB_MSGS_.", '".
time()."', '".$login."','".$message."' )" );
mysql_query( "UPDATE MINICHAT SET NB=NB-1" );
mysql_query( "DELETE FROM MINICHAT WHERE NB < 1" );
}
// Returns messages
function getMessages() {
$rs = mysql_query( "SELECT * FROM MINICHAT ORDER BY NB" );
$ret = Array();
while ( $msg = mysql_fetch_array( $rs )) {
$ret[] = date( 'h:m', $msg['ITSTIME'] )." ".$msg['LOGIN']." >".$msg['MESSAGE'];
}
return $ret;
}
// Prints mini chat
function miniChat() {
$msgs = getMessages();
@reset( $msgs );
echo '<form method="post">
<table border="0" bgcolor="#000000" cellpadding="1">
<tr><td>
<table border="0" bgcolor="#ffffff" cellpadding="1">
';
while ( list(,$msg) = each( $msgs ))
echo "<tr><td>$msg</td></tr>";
if ( !$_COOKIE['minichatlogin'] ) {
if ( !$_POST['login'] )
echo '<tr><td>Login:<input type="text" name="login" size="6"></td></tr>';
else
echo '<input type="hidden" name="login" value="'.$_POST['login'].'">';
}
echo '
<tr><td><input type="text" name="msg" size="10"></td></tr>
<tr><td align="center"><input type="submit" value="Send"></td></tr>
</table></tr></td></table></form>';
}
// Message Posted ?
if ( isset( $_POST['msg'] )) {
addMessage( $_POST['login'], $_POST['msg'] );
}
?>
<html>
<head>
<title>Mini Chat Sample</title>
</head>
<body>
<center>
<?php miniChat(); ?>
<hr>
<a href="mailto:greggory@free.fr">Contact</a>
</center>
</body>
</html>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Discussion Board Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing. FREE! Go There Now!
|
|
|
|
Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |