Hallo,
Ik heb voor jullie een opensource chat
JE MAG HEM GEBRUIKEN MAAR NIET VERKOPEN!
JE MAG OOK NIET MIJN NAAM VERWIJDEREN
Versie: 0.1.3
Je zult hem zelf moeten aanpassen voor in je systeem.
Dit script werkt enkel met 2 personen. Bij meerdere personen worden berichten niet weergeven.
Voorbeeld: Klik
MySQL:
Chat.php:
Veel plezier dermee
Ik heb voor jullie een opensource chat

JE MAG HEM GEBRUIKEN MAAR NIET VERKOPEN!
JE MAG OOK NIET MIJN NAAM VERWIJDEREN
Versie: 0.1.3
Je zult hem zelf moeten aanpassen voor in je systeem.
Dit script werkt enkel met 2 personen. Bij meerdere personen worden berichten niet weergeven.
Voorbeeld: Klik
MySQL:
CREATE TABLE IF NOT EXISTS `chat` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` text NOT NULL,
`bericht` text NOT NULL,
`gelezen` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Chat.php:
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
*
* @author Milan Drossaerts
* @copyright 2010
* @license Opensource, je mag mijn naam niet verwijderen
* @version 0.1.3
*
*/
//Verbinden met database:[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]localhost[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]---[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]---[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]---[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]//Kijken of er een request wordt gedaan:[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ajax[/COLOR][COLOR= #007700]]) && ![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ajax[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ip[/COLOR][COLOR= #007700]]) && ![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ip[/COLOR][COLOR= #007700]]) && ![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]))
{[/COLOR]
[COLOR= #FF8000]//Nieuwe bericht ophalen:[/COLOR]
[COLOR= #0000BB]$mQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id, ip, bericht FROM chat WHERE ip != "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]" AND gelezen = 0 "[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[COLOR= #FF8000]//While maken met nieuwe berichten[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$mFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$mQuery[/COLOR][COLOR= #007700]))
{[/COLOR]
[COLOR= #FF8000]//Kijken wat er moet worden weergeven[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]] !=[/COLOR] [COLOR= #0000BB]$mFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ip[/COLOR][COLOR= #007700]])
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Andere: [/COLOR] [COLOR= #007700].[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$mFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Jij: [/COLOR] [COLOR= #007700].[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$mFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR]
[COLOR= #FF8000]//Bericht op gelezen zetten[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE chat SET gelezen = 1 WHERE id = "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$mFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
}
}[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ajax[/COLOR][COLOR= #007700]]) && ![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ajax[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]) && ![/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]))
{[/COLOR]
[COLOR= #FF8000]//Nieuw bericht toevoegen:[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO chat (ip,bericht) VALUES ("[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]", "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]")"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Jij:[/COLOR] [COLOR= #007700].[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]bericht[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
[COLOR= #FF8000]//Chat dus:[/COLOR]
?>
<script type="text/javascript">
/**
+-----------------+------------------------------------------------+
| Author: | Milan Drossaerts |
+-----------------+------------------------------------------------+
| Copyright: | 2010 |
+-----------------+------------------------------------------------+
| License: | Opensource, je mag mijn naam niet verwijderen |
+-----------------+------------------------------------------------+
*/
function get_messages()
{
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!=undefined) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
xmlhttp.open("GET", "chat.php?ajax=true&ip=[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REMOTE_ADDR[/COLOR][COLOR= #007700]];[/COLOR] ?>",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.responseText != )
{
document.getElementById(chat).innerHTML += xmlhttp.responseText;
setTitle("1");
}
var chat = document.getElementById("chat");
chat.scrollTop = chat.scrollHeight;
}
}
xmlhttp.send(null);
setTimeout(get_messages(),1500);
}
setTimeout(get_messages(),1500);
function post_messages(bericht)
{
var xmlhttpe=false;
if (!xmlhttpe && typeof XMLHttpRequest!=undefined) {
try {
xmlhttpe = new XMLHttpRequest();
} catch (e) {
xmlhttpe=false;
}
}
if (!xmlhttpe && window.createRequest) {
try {
xmlhttpe = window.createRequest();
} catch (e) {
xmlhttpe=false;
}
}
xmlhttpe.open("GET", "chat.php?ajax=true&bericht=" + bericht + "",true);
xmlhttpe.onreadystatechange=function() {
if (xmlhttpe.readyState==4) {
document.getElementById(chat).innerHTML += xmlhttpe.responseText;
set_div(Bericht is geplaatst,0);
document.getElementById(button).style.disabled = none;
document.getElementById(button).style.value = Plaats bericht;
document.getElementById(bericht).value = ;
var chat = document.getElementById("chat");
chat.scrollTop = chat.scrollHeight;
}else{
set_div(Laden...,0);
}
}
xmlhttpe.send(null);
}
function set_div(bericht,number)
{
if (number == 0)
{
document.getElementById(status).innerHTML = bericht;
setTimeout(set_div(" + bericht + ","1"),4000);
}else{
document.getElementById(status).innerHTML = ;
}
}
var title = 1;
function setTitle(nummer)
{
if (nummer == 1)
{
document.getElementById(titel).innerHTML = **** Nieuw bericht | Chat ****;
title = title+1;
if (title == 10)
{
//5 seconden geweest, dus stoppen we met titel aanpassen :)
document.getElementById(titel).innerHTML = Chat;
title = 1;
}else{
setTimeout(setTitle("2"),500);
}
}else{
document.getElementById(titel).innerHTML = ____ Nieuw bericht | Chat ____;
title = title+1;
if (title == 10)
{
//5 seconden geweest, dus stoppen we met titel aanpassen :)
document.getElementById(titel).innerHTML = Chat;
title = 1;
}else{
setTimeout(setTitle("1"),500);
}
}
}
</script>
<title id="titel">Chat</title>
<div id="chat" style="width: 900px; height: 400px; border: 1px #C0C0C0 solid; overflow: auto;" ></div>
<div id="status" style="height: 20px;"></div><br />
<form method="post" onsubmit="post_messages(this.bericht.value); document.getElementById(bericht).innerHTML = ; document.getElementById(button).style.disabled = disabled; document.getElementById(button).innerHTML = Laden...; return false">
Bericht:<br />
<textarea style="width: 400px; height: 80px;" id="bericht"></textarea><br />
<input type="submit" name="submit" id="button" value="Plaats bericht" />
</form>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?> Veel plezier dermee

