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! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |