By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,061 Members | 432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,061 IT Pros & Developers. It's quick & easy.

PHP Chat

P: 134
Alright, I've set up a chat system that only works half way... I need suggestions on how to make it work better...

I'm trying to figure out a way to make $_SESSION['chat'] viewable to all players by making it equal $cchat, but I don't think it will work... I don't like to use the database because then the chat would become really tangled. It's only there for admin access. I want to keep the chat session specific while having what is posted viewable to other people that are in the immediate area only at the time that you post it.

$newchat="INSERT INTO `logs`(`who`, `towho`, `posted`, `when`) VALUES ('$otheruser', '$mesgread[2]', '$msg', '$time')";
$mesgread=explode(" ", $msg, 4);
$saynum=mysql_num_rows(mysql_query("SELECT *
FROM `user_table`
WHERE `cn`='$mesgread[2]'
AND `ns`='$x'
AND `ew`='$y'
AND `ud`='$z'"));
//Emote Command
if ($mesgread[0]=="/" AND $user!=$otheruser) {
$emote=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat'].ucfirst($otheruser)." ".stripslashes($emote[1])."<br>";
} elseif ($mesgread[0]=="/" AND $user==$otheruser) {
$emote=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat']."<b>You ".$emote[1]."</b><br>";
echo $META;
//Say Command
if ($mesgread[0]=="Say" OR $mesgread[0]=="say" AND $mesgread[1]!="to" AND $user!=$otheruser) {
$say=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat'].ucfirst($otheruser)." said, \"".$say[1]."\"<br>";
} elseif ($mesgread[0]=="Say" OR $mesgread[0]=="say" AND $mesgread[1]!="to" AND $user==$otheruser) {
$say=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat']."<b>You said, \"".$say[1]."\"</b><br>";
echo $META;
if ($mesgread[0]=="Shout" OR $mesgread[0]=="shout" AND $mesgread[1]!="to" AND $user!=$otheruser) {
$shout=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat'].ucfirst($otheruser)." shouted, \"".$shout[1]."\"<br>";
} elseif ($mesgread[0]=="Shout" OR $mesgread[0]=="shout" AND $mesgread[1]!="to" AND $user==$otheruser) {
$shout=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat']."<b>You shouted, \"".$shout[1]."\"</b><br>";
echo $META;
//Look At Person
if ($mesgread[0]=="look" AND $mesgread[1]=="at") {
//If the user has nothing to do with the look at...
if ($user!=$otheruser AND $user!=$mesgread[2]) {
$_SESSION['chat']=$_SESSION['chat'].ucfirst($otheruser)." looked at ".$mesgread[2]."<br>";
//If the user playing is the poster...
if ($user==$otheruser) {
$_SESSION['chat']=$_SESSION['chat']."<b>You looked at ".ucfirst($mesgread[2]).".</b><br>";
$lookfetch="SELECT * FROM `user_table` WHERE `cn`='$mesgread[2]'";
$echolook="<i>".ucfirst($mesgread[2])."</i> is a <i>".strtolower($larry[12])." ".$larry[4]."</i> and, from what can be gathered, a <i>".$larry[3]."</i>.
<i>".ucfirst($larry[1])."</i> looks to be <i>".$larry[6]."</i> in height, <i>".$larry[7]."</i> in weight, and appears <i>".$larry[8]."</i>.
<i>".ucfirst($larry[1])."</i> is also <i>".$larry[10]."</i> with <i>".$larry[9]."</i> eyes, <i>".$larry[11]."</i> skin, and <i>".$larry[5]."</i> hair.";
echo $META;
//If the user playing is different from the poster but is the target...
if ($user!=$otheruser AND $user==$mesgread[2]) {
$_SESSION['chat']=$_SESSION['chat']."<b>".ucfirst($otheruser)." looked at you.</b><br>";
//Clear the current chat...
if ($mesgread[0]=="clear" OR $mesgread[0]=="Clear") {
echo "<META HTTP-EQUIV='refresh' content='0; url=clear.php'>";
echo $cchat;
Mar 6 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.