Mini Chat PHP Script

Any problem with PHP can be disscused here
blue-sky
Posts: 33
Joined: Tue Jun 12, 2007 3:41 pm

Mini Chat PHP Script

Post by blue-sky »

Mini Chat PHP Script

Code: Select all

<?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 '', 
  PRIMARY KEY  (NB), 
  UNIQUE KEY NB (NB), 
  KEY NB_2 (NB) 
); 
*/ 

// 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 ( '10', '".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>'; 
} 
?> 
<html> 
<head> 
<title>Mini Chat Sample</title> 
</head> 
<body> 
<?php miniChat(); ?> 
</body> 
</html>


anish
Posts: 353
Joined: Fri Apr 27, 2007 12:34 pm
Contact:

Post by anish »

Thanks thats a simple and cool script.
Shahul
Posts: 58
Joined: Fri Jun 15, 2007 1:58 pm

Post by Shahul »

Thanks a lot friend , i also got a another script but their is problem when i installed it , anyway i am going to use this..Thanks a million..

Shahul
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

This is really great to use for like a shoutbox on a site. ;)
sakhan
Posts: 217
Joined: Sat May 26, 2007 6:02 am

Post by sakhan »

thanks for sharing i will check this one
thetarget
Posts: 496
Joined: Sat Jul 09, 2005 9:10 am

Post by thetarget »

wow blue-sky. Nice script.

A little tweak about browser caching and it is ready to go
Gyanu
Posts: 338
Joined: Mon Jul 30, 2007 2:03 pm
Contact:

Post by Gyanu »

i think this coding is not sufficient.
Image
Niaoson
Posts: 10
Joined: Fri Sep 07, 2007 4:20 pm

Post by Niaoson »

Not sure if that script does the job.. But I think it'll be cool if it records down the chat log too
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

Gyanu wrote:i think this coding is not sufficient.

Yeah, I just looked over it again and it is HORRIBLE. :/

You don't really check if a chat is posted, etc. Also, we don't have that database constants file and that isn't needed.

And finally, sql injections can be EASILY done on that...especially spammers. :/
Zeqya
Posts: 155
Joined: Mon Aug 20, 2007 6:36 pm

Post by Zeqya »

Cool You Made It?You Know How To Make A Login For Being Able To Chat At The Cat?
Want A Nice Website With A Forum
Dont **** Unless You Want To Die If You're Already Dead Then Ok
Wanna Make Colors Too?BBcode
Locked