Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Super-mini Chat room Jump to:  
Category: >> PHP Code >> Super-mini Chat room Bookmark and Share

<< lastnext >>

Snippet Name: Super-mini Chat room

Description: A super small, super simple chat room. No security, so use at your own risk.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?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> 
</center> 
</body> 
</html>
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 223 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?