470,820 Members | 1,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,820 developers. It's quick & easy.

PHP Chat

The1corrupted
134 100+
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.

[PHP]
/*CHAT SYSTEM*/
$otheruser=$_POST['poster'];
$newchat="INSERT INTO `logs`(`who`, `towho`, `posted`, `when`) VALUES ('$otheruser', '$mesgread[2]', '$msg', '$time')";
$msg=$_POST['msg'];
$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>";
mysql_query($newchat);
} elseif ($mesgread[0]=="/" AND $user==$otheruser) {
$emote=explode(" ", $msg, 2);
$_SESSION['chat']=$_SESSION['chat']."<b>You ".$emote[1]."</b><br>";
echo $META;
mysql_query($newchat);
}
//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>";
mysql_query($newchat);
} 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;
mysql_query($newchat);
}
//Shout
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>";
mysql_query($newchat);
} 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;
mysql_query($newchat);
}
//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]'";
$larry=mysql_fetch_array(mysql_query($lookfetch));
$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'>";
}
$cchat=$_SESSION['chat'];
echo $cchat;
[/PHP]
Mar 6 '07 #1
0 1607

Post your reply

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

Similar topics

2 posts views Thread by Savas Ates | last post: by
reply views Thread by Zeppo | last post: by
3 posts views Thread by John Wright | last post: by
3 posts views Thread by A | last post: by
oll3i
1 post views Thread by oll3i | last post: by
oll3i
1 post views Thread by oll3i | last post: by
4 posts views Thread by Gandalf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.