Voici pour le code
ceci est le script qui rassemblera les deux chat php :
<?php
<html>
<link href="./style2.css" rel="stylesheet" type="text/css" />
<head>
</head>
<body>
<div id="menu_fond">
<? include('chat1/chat_client_1.php'); ?>
</div>
<div id="cadre">
<? include('chat2/chat_client_2.php'); ?>
</div>
</body>
</html>
php ?>
Et voici le code de mon premier chat :
<?<?php
function createForm1()
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center">
<tr><td colspan="2"> </td></tr>
<tr><td>Votre prénom : </td>
<td><input class="text" type="text" name="name" /></td></tr>
<tr><td colspan="2" align="center">
<input class="text" type="submit" name="submitBtn" value="Login" />
</td></tr>
</table>
</form>
<?php
}
if (isset($_GET['u']))
{
unset($_SESSION['nickName1']);
}
// Gestion Du pseudo
if (isset($_POST['submitBtn']))
{
$name = isset($_POST['name']) ? $_POST['name'] : "Profil";
$_SESSION['nickName1'] = $name;
}
$nickName1 = isset($_SESSION['nickName1']) ? $_SESSION['nickName1'] : "Caché";
?>
<html>
<head>
<title>Chat </title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
var httpObject1 = null;
var link1 = "";
var timerID1 = 0;
var nickName1 = "<?php echo $nickName1; ?>";
function gethttpObject1()
{
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else
{
alert("Votre navigateur ne supporte pas l'AJAX.");
return null;
}
}
function setOutput1()
{
if(httpObject1.readyState == 4)
{
var response1 = httpObject1.responseText;
var objDiv1 = document.getElementById("result");
objDiv1.innerHTML += response1;
objDiv1.scrollTop = objDiv1.scrollHeight;
var inpObj1 = document.getElementById("msg");
inpObj1.value = "";
inpObj1.focus();
}
}
function setAll1()
{
if(httpObject1.readyState == 4)
{
var response1 = httpObject1.responseText;
var objDiv1 = document.getElementById("result");
objDiv1.innerHTML = response1;
objDiv1.scrollTop = objDiv1.scrollHeight;
}
}
function doWork1()
{
httpObject1 = gethttpObject1();
if (httpObject1 != null)
{
link1 = "message_1.php?nick="+nickName1+"&msg="+document.getElementById('msg').value;
httpObject1.open("GET", link1 , true);
httpObject1.onreadystatechange = setOutput1;
httpObject1.send(null);
}
}
function doReload1()
{
httpObject1 = gethttpObject1();
var randomnumber=Math.floor(Math.random()*10000);
if (httpObject1 != null)
{
link1 = "message_1.php?all=1&rnd="+randomnumber;
httpObject1.open("GET", link1 , true);
httpObject1.onreadystatechange = setAll1;
httpObject1.send(null);
}
}
function UpdateTimer1()
{
doReload1();
timerID1 = setTimeout("UpdateTimer1()", 5000);
}
</script>
</head>
<body onload="UpdateTimer1();">
<div id="main">
<div id="caption">Chat</div>
<div id="icon"> </div>
<?php
if (!isset($_SESSION['nickName1']) )
{
createForm1();
} else
{
$name1 = isset($_POST['name1']) ? $_POST['name1'] : "Unnamed";
$_SESSION['nickName1'] = $name1;
?>
<div id="result">
<?php
$data1= file("msg_1.html");
foreach ($data1 as $line1)
{
echo $line1;
}
?>
</div>
<div id="sender" >
Votre message: <input type="text" name="msg" size="30" maxlength="50" id="msg" />
<button onclick="doWork1();">Ecrire</button>
</div>
<?php
}
?>
</div>
</body> ?>
et voici le code qui envoie le message:
<?php
IF (!ISSET($_SESSION))
{
SESSION_START();
}
if ( empty($_GET['msg']) )
{
}
else
{
}
$_SESSION['last_session_request'] = TIME();
if (isset($_GET['msg']))
{
if (file_exists('msg_1.html'))
{
$f1 = fopen('msg_1.html',"a+");
} else
{
$f1 = fopen('msg_1.html',"w+");
}
$nick = isset($_GET['nick']) ? $_GET['nick'] : "Hidden";
$msg = isset($_GET['msg']) ? htmlspecialchars($_GET['msg']) : ".";
$line1 = "<p><span class=\"name\">$nick: </span><span class=\"txt\">$msg</span></p>";
fwrite($f1,$line1."\r\n");
fclose($f1);
echo $line1;
} else if (isset($_GET['all']))
{
$flag1 = file('msg_1.html');
$content1 = "";
foreach ($flag1 as $value)
{
$content1 .= $value;
}
echo $content1;
}
?>
j'ai le même code pour le deuxième chat j'ai juste renommé les variables et fonctions de celui ci avec un 1 derrière pour pas qu'il y est de problème en vain le problème et toujours présent