PHP interesse |
|
ik heb nu dit:
<?php
$date = date("d_m_Y", time());
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Shoutbox</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var xmlhttp = null;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
window.alert("Uw browser ondersteunt het XMLHttpRequest object niet!");
}
}
function getTXT(){
xmlhttp.open("GET", "archive/shoutbox_<?=$date; ?>.txt", true);
xmlhttp.onreadystatechange = showTXT;
xmlhttp.send('');
}
function showTXT(){
if(xmlhttp.readyState == 4){
document.getElementById('shoutbox').innerHTML = xmlhttp.responseText;
}
}
</script>
</head>
<body>
<?php
$date = date("d_m_Y", time());
if(!file_exists('archive/shoutbox_'.$date.'.txt')) {
$file = fopen('archive/shoutbox_'.$date.'.txt', "w+");
fputs($file, "");
fclose($file);
header("Location: index.php");
}else{
if(isset($_POST['verzend'])) {
$name = $_POST['name'];
setcookie("tbsites_shoutbox_name", $name);
$time = date("d-m-Y H:i:s", time());
$item = $_POST['item'];
$file = fopen('archive/shoutbox_'.$date.'.txt', "r+");
$oldfile = file_get_contents('archive/shoutbox_'.$date.'.txt');
fputs($file, $oldfile."<table style='width: 100%; border: 1px dotted #CCCCCC;'>
<tr bgcolor=\"#87C53E\">
<td width='75%'>".$name."</td>
<td width='15%'>".$time."</td>
<tr bgcolor=\"#87C53E\">
<td width='100%' colspan='2'>".$item."</td></tr>
</table>
");
fclose($file);
}
$shoutbox = file_get_contents("archive/shoutbox_".$date.".txt");
echo '<div style="width: 100%; height: 500px; overflow:auto;">';
?>
<script type="text/javascript">
getTXT();
</script>
<div id="shoutbox">
</div>
<?php
echo '</div>';
?>
<form action="index.php" method='post'>
<input type="text" name="name" value='Naam' style="width: 20%; float: left;"/>
<input type="text" name="item" value='Bericht' style="width: 80%; float: right;"/><br />
<input type="submit" name="verzend" value="Plaats! " style="text-align: center;"/ >
</form>
<?php
}
?>
</body>
</html>
<?php ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Shoutbox</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> var xmlhttp = null; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ window.alert("Uw browser ondersteunt het XMLHttpRequest object niet!"); } } function getTXT(){ xmlhttp.open("GET", "archive/shoutbox_<?=$date; ?>.txt", true); xmlhttp.onreadystatechange = showTXT; xmlhttp.send(''); } function showTXT(){ if(xmlhttp.readyState == 4){ document.getElementById('shoutbox').innerHTML = xmlhttp.responseText; } } </script> </head> <body> <?php $file = fopen('archive/shoutbox_'.$date.'.txt', "w+"); header("Location: index.php"); }else{ if(isset($_POST['verzend'])) { $name = $_POST['name']; $item = $_POST['item']; $file = fopen('archive/shoutbox_'.$date.'.txt', "r+"); fputs($file, $oldfile."<table style='width: 100%; border: 1px dotted #CCCCCC;'> <tr bgcolor=\"#87C53E\"> <td width='75%'>".$name."</td> <td width='15%'>".$time."</td> <tr bgcolor=\"#87C53E\"> <td width='100%' colspan='2'>".$item."</td></tr> </table> "); } echo '<div style="width: 100%; height: 500px; overflow:auto;">'; ?> <script type="text/javascript"> getTXT(); </script> <div id="shoutbox"> </div> <?php ?> <form action="index.php" method='post'> <input type="text" name="name" value='Naam' style="width: 20%; float: left;"/> <input type="text" name="item" value='Bericht' style="width: 80%; float: right;"/><br /> <input type="submit" name="verzend" value="Plaats! " style="text-align: center;"/ > </form> <?php } ?> </body> </html>
dit werkt.
maar alleen ik wil dus als iemand anders een bericht plaatst dat ik dan de pagina niet hoef te vernieuwen om het bericht te zien....
Weet iemand hoe dit moet?
[edit]
Het is gelukt: setInterval(getTXT, 500);
[/edit] |