Me ha sorprendido ver que en el momento que me envian el archivo con los procesos tengo solo 3 personas en mi web, pero que el proceso del chat se esta ejecutando mas de 40 veces y encima por ip que ni estan en ese momento en la web ... ¿no es raro?.
Os pongo aqui el chat, a ver si veis que tengo mal, que seguro que algo tengo mal ...
Código PHP:
<?
// aqui defino la forma de session
require 'includes/session.php';
// Aqui defino el string de conexion
require 'includes/connectdb.php';
// aqui defino el idioma
require 'includes/es.php';
if ($_GET['activarchat'] == 1)
$_SESSION['estadochat'] = 1;
if ($_SESSION['estadochat'] <> 1)
{
?>
<style>
body {
overflow-x:hidden;
background-color:rgb(213,225,240)
}
.chat_bloqueado {
font-size: 11px;
font-family: verdana, Geneva, Arial;
}
</style>
<div class=chat_bloqueado>
<center>
<p class=chat_bloqueado>Chat Bloqueado</p>
<p class=chat_bloqueado>si deseas activar el chat <a href=chat_mini.php?activarchat=1&chat=<?echo $_GET['chat'];?>&chat2=<?echo $_GET['chat2'];?>>presiona aquí</a></p>
</center>
</div>
<?
exit;
}
require_once("xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->registerFunction("myFunction");
$xajax->registerFunction("funcion_barranavegacion");
$chat = "principal";
function f_chat($texto, $chat, $id_chat)
{
// Aqui guardamos datos.
if ($texto <> "")
{
//$fecha=date("Y/m/d - H:i:s");
//Obtenemos la fecha actual:
$fecha=time();
//Queremos restar 3 horas a la fecha actual:
$horas = 7;
// Convertimos las horas a segundos y las sumamos:
$fecha += ($horas * 60 * 60);
// Le damos al resultado el formato deseado:
$fecha = date("Y-m-d H:i:s", $fecha );
$insert="insert into chat (chat, comentario, fecha, usuario) values ('".$chat."','".htmlentities(utf8_decode($texto))."','".$fecha."', '".$_SESSION['nick']."')";
mysql_query($insert);
}
// Comprobar que no veas el chat que no tienes acceso.
if ($chat <> "principal") {
$tmpQuery = mysql_query("select count(gameID) from games where gameID = '".$chat."' and (whitePlayer = ".$_SESSION['playerID']." or blackPlayer = ".$_SESSION['playerID'].")");
$max_id = mysql_result($tmpQuery,0);
if ($max_id == 0)
{
exit;
}
}
// aqui para el tiempo
if ($chat == "principal") {
// el chat principal lo pongo poco tiempo el resto mucho.
$tiempo = "20001";
} else {
$tiempo = "160001";
}
// validar que si ya se cargo el chat no lo vuelva a cargar.
// aqui cargamos el chat.
$tmpQuery = mysql_query("select count(id) from chat where chat = '".$chat."'");
$max_id = mysql_result($tmpQuery,0);
$cargarchat = 0;
if ($id_chat == "" ) {
$id_chat = $max_id;
$cargarchat = 1;
} else {
if ($id_chat <> $max_id)
{
$id_chat = $max_id;
$cargarchat = 1;
}
}
if ($max_id == 0)
$cargarchat = 1;
if ($cargarchat == 1) {
$select="select * from chat where chat = '".$chat."' order by id desc limit 20";
$select=mysql_query($select);
while($row = mysql_fetch_array($select))
{
$mensaje = $row["comentario"];
$usuario = $row["usuario"];
$usuario = str_replace("á", "a", $usuario);
$usuario = str_replace("é", "e", $usuario);
$usuario = str_replace("í", "i", $usuario);
$usuario = str_replace("ó", "o", $usuario);
$usuario = str_replace("ú", "u", $usuario);
$ver = $ver."<div class=chat><b>".$usuario."</b><br>".$mensaje."<br /></div>";
}
if ($ver == "")
$ver = _nohaymensajesenelchat.".";
$objResponse = new xajaxResponse();
$objResponse->call('setTimeout','xajax_f_chat("", "'.$chat.'", "'.$id_chat.'");',$tiempo);
$objResponse->assign("ventanachat","innerHTML", $ver);
$objResponse->assign("id_chat","value",$id_chat);
return $objResponse;
} else {
$objResponse = new xajaxResponse();
$objResponse->call('setTimeout','xajax_f_chat("", "'.$chat.'", "'.$id_chat.'");',$tiempo);
return $objResponse;
}
}
$xajax->registerFunction("f_chat");
$xajax->processRequest();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" dir="ltr" lang="es">
<head>
<title>MiniChat</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta NAME="language" CONTENT="es" />
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="./css/layout4_setup_sinlateral.css" />
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="./css/layout4_text.css" />
<style>
body {
overflow-x:hidden;
/*background : rgb(213,225,240);*/
background-color:rgb(213,225,240)
}
.blue {width:183px; margin:0 0 2.5em 0; padding:0 0 10px 0; border:solid 1px rgb(137,170,214); background-color:rgb(213,225,240);}
#ventanachat h1, #ventanachat h2 {
color : #cc0000;
}
#ventanachat {
right:0px;
position : fixed;
top : 10%;
bottom : 100px;
margin : 30px 0px 0px 0px;
width : 200px;
height : 200px;
color : #000000;
overflow : auto;
}
.innertube{
margin: 15px; /*Margins for inner DIV inside each DIV (to provide padding)*/
}
.chat
{
color:#000000;
font-size:7pt;
padding: 7px;
margin: 5px;
font-weight : normal;
letter-spacing : 2px;
border: 1px solid #b8d957;
background-color: #ecf2e0;
text-align: left;
}
.actions{
margin-left: 10px;
margin-top: 10px;
}
</style>
<?php $xajax->printJavascript(); ?>
</head>
<body>
<?
// antes de nada comprobar que haya chat.
$tmpOpponentEmail = mysql_query("SELECT id from datos_generales where chatactivo = 1");
if (mysql_num_rows($tmpOpponentEmail) == 0)
{
echo "<br><br><br><br><b class=aviso>Chat bloqueado por los administradores.</b>";
exit;
}
?>
<script language="JavaScript" type="text/javascript">
<!--
function enviarmensaje(mensaje, id_chat)
{
document.getElementById('e1').value="";
document.getElementById('e1').focus();
xajax_f_chat(mensaje, "<?echo $chat;?>", id_chat);
}
function keyDown(e, id_chat) {
var name = "";
if (document.all) {
if (e.keyCode == 13) name = e.srcElement.name;
} else
if (e.which == 13) name = e.target.name;
if ((name.length > 0) && (name.length < 6)){
xajax_f_chat(document.getElementById('e1').value, "<?echo $chat;?>", id_chat);
document.getElementById('e1').value="";
document.getElementById('e1').focus();
}
}
function setsmiley(what){
tmp=document.getElementById("e1");
tmp.value = tmp.value+" "+what+" ";
tmp.focus();
}
// -->
</script>
<div class="actions">
<a href="javascript:setsmiley(':)')"><img src="img/chat/smile.gif" border="0" alt=":)" align="bottom"></a>
<a href="javascript:setsmiley(':p')"><img src="img/chat/tongue.gif" border="0" alt=":p" align="bottom"></a>
<a href="javascript:setsmiley(';)')"><img src="img/chat/wink.gif" border="0" alt=";)" align="bottom"></a>
<a href="javascript:setsmiley(':o')"><img src="img/chat/icon_e_surprised.gif" border="0" alt=":(" align="bottom"></a>
<a href="javascript:setsmiley(':-(')"><img src="img/chat/icon_mad.gif" border="0" alt=":(" align="bottom"></a>
<input name="e1" id="e1" type="text" size="20" maxlength="150" onkeydown="javascript:keyDown(event, document.getElementById('id_chat').value);">
<input type="button" value="*" onclick="enviarmensaje(document.getElementById('e1').value, document.getElementById('id_chat').value)" />
<input type="hidden" id="id_hash" value="" />
<input type="hidden" id="id_chat" value="0" />
</div>
<div id="ventanachat">
<div class="innertube">
<br><br><br><center>Cargando Chat.</center>
</div>
</div>
<script type="text/javascript">
document.getElementById('e1').value="";
document.getElementById('e1').focus();
xajax_f_chat("", "<?echo $chat;?>",0);
</script>
</body></html>
<? mysql_close(); ?>