PHP Chat

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The1corrupted
    New Member
    • Feb 2007
    • 134

    PHP Chat

    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=$_PO ST['poster'];
    $newchat="INSER T INTO `logs`(`who`, `towho`, `posted`, `when`) VALUES ('$otheruser', '$mesgread[2]', '$msg', '$time')";
    $msg=$_POST['msg'];
    $mesgread=explo de(" ", $msg, 4);
    $saynum=mysql_n um_rows(mysql_q uery("SELECT *
    FROM `user_table`
    WHERE `cn`='$mesgread[2]'
    AND `ns`='$x'
    AND `ew`='$y'
    AND `ud`='$z'"));
    //Emote Command
    if ($mesgread[0]=="/" AND $user!=$otherus er) {
    $emote=explode( " ", $msg, 2);
    $_SESSION['chat']=$_SESSION['chat'].ucfirst($other user)." ".stripslashes( $emote[1])."<br>";
    mysql_query($ne wchat);
    } elseif ($mesgread[0]=="/" AND $user==$otherus er) {
    $emote=explode( " ", $msg, 2);
    $_SESSION['chat']=$_SESSION['chat']."<b>You ".$emote[1]."</b><br>";
    echo $META;
    mysql_query($ne wchat);
    }
    //Say Command
    if ($mesgread[0]=="Say" OR $mesgread[0]=="say" AND $mesgread[1]!="to" AND $user!=$otherus er) {
    $say=explode(" ", $msg, 2);
    $_SESSION['chat']=$_SESSION['chat'].ucfirst($other user)." said, \"".$say[1]."\"<br>";
    mysql_query($ne wchat);
    } elseif ($mesgread[0]=="Say" OR $mesgread[0]=="say" AND $mesgread[1]!="to" AND $user==$otherus er) {
    $say=explode(" ", $msg, 2);
    $_SESSION['chat']=$_SESSION['chat']."<b>You said, \"".$say[1]."\"</b><br>";
    echo $META;
    mysql_query($ne wchat);
    }
    //Shout
    if ($mesgread[0]=="Shout" OR $mesgread[0]=="shout" AND $mesgread[1]!="to" AND $user!=$otherus er) {
    $shout=explode( " ", $msg, 2);
    $_SESSION['chat']=$_SESSION['chat'].ucfirst($other user)." shouted, \"".$shout[1]."\"<br>";
    mysql_query($ne wchat);
    } elseif ($mesgread[0]=="Shout" OR $mesgread[0]=="shout" AND $mesgread[1]!="to" AND $user==$otherus er) {
    $shout=explode( " ", $msg, 2);
    $_SESSION['chat']=$_SESSION['chat']."<b>You shouted, \"".$shout[1]."\"</b><br>";
    echo $META;
    mysql_query($ne wchat);
    }
    //Look At Person
    if ($mesgread[0]=="look" AND $mesgread[1]=="at") {
    //If the user has nothing to do with the look at...
    if ($user!=$otheru ser AND $user!=$mesgrea d[2]) {
    $_SESSION['chat']=$_SESSION['chat'].ucfirst($other user)." looked at ".$mesgread[2]."<br>";
    }
    //If the user playing is the poster...
    if ($user==$otheru ser) {
    $_SESSION['chat']=$_SESSION['chat']."<b>You looked at ".ucfirst($mesg read[2]).".</b><br>";
    $lookfetch="SEL ECT * FROM `user_table` WHERE `cn`='$mesgread[2]'";
    $larry=mysql_fe tch_array(mysql _query($lookfet ch));
    $echolook="<i>" .ucfirst($mesgr ead[2])."</i> is a <i>".strtolower ($larry[12])." ".$larry[4]."</i> and, from what can be gathered, a <i>".$larry[3]."</i>.
    <i>".ucfirst($l arry[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($l arry[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!=$otheru ser AND $user==$mesgrea d[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=$_SESSIO N['chat'];
    echo $cchat;
    [/PHP]
Working...