Gastenboek met admin
Auteur: GTW - 19 maart 2006 - 17:49 - Gekeurd door: nemesiskoen - Hits: 19674 - Aantal punten: 4.29 (7 stemmen)
Dit script bestaat uit 4 pagina's:
- De index
- De admin
- De style
- De config
Met de admin kun je berichten uit de database/het gastenboek verwijderen.
De preview is met banner, het origineel is zonder.
Edit:Ik heb er even een ipblocker ingebouwd en de berichten worden nu gesorteerd zodat de nieuwste bovenaan staat
|
Code: |
<------------------>
De tabel:
<------------------>
CREATE TABLE `gastenboek` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
`van` VARCHAR( 255 ) NOT NULL ,
`datum` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`website` VARCHAR( 255 ) NOT NULL ,
`bericht` VARCHAR( 255 ) NOT NULL ,
`ip` VARCHAR( 15 ) NOT NULL ,
UNIQUE ( `id` )
) TYPE = MYISAM ;
CREATE TABLE `gastenboek` ( `id` INT( 8 ) NOT NULL AUTO_INCREMENT , `van` VARCHAR( 255 ) NOT NULL , `datum` VARCHAR( 50 ) NOT NULL , `email` VARCHAR( 255 ) NOT NULL , `website` VARCHAR( 255 ) NOT NULL , `bericht` VARCHAR( 255 ) NOT NULL , `ip` VARCHAR( 15 ) NOT NULL , UNIQUE ( `id` ) ) TYPE = MYISAM ;
<------------------>
Index.php
<------------------>
<?
include"config.php";
$haalaantal = mysql_num_rows(mysql_query("SELECT * FROM gastenboek"));
$ip = $_SERVER['REMOTE_ADDR'];
$error = "";
if(isset($_GET['post'])and($_GET['post']=="1")){
if(empty($_POST['naam'])){
$error .= "<tr><td colspan=\"2\"><font color=\"red\">Geen naam ingevuld</font></td></tr>";}
if(empty($_POST['naam'])){
$error .= "<tr><td colspan=\"2\"><font color=\"red\">Geen bericht ingevuld</font></td></tr>";}
if(!empty($_POST['naam'])and(!empty($_POST['bericht']))){
$insert = "INSERT INTO gastenboek (van, datum, email, website, bericht, ip) VALUES ('".$_POST['naam']."', '".$_POST['datum']."', '".$_POST['email']."', '".$_POST['website']."', '".$_POST['bericht']."', '".$ip."')";
if(mysql_query($insert)){
$error = "<tr><td colspan=\"2\" align=\"center\"><font color=\"green\">Alles is correct ingevuld</font></td></tr>";
}
}
}
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Gastenboek</title>
</head>
<body>
<center>
<!-- gastenboek zelf -->
<table cellspacing="0" width="300px">
<tr>
<td colspan="2" align="center"><font class="header">Gastenboek</font></td>
</tr>
<tr>
<td colspan="2" align="center"><font class="header">Aantal berichten:<?=$haalaantal;?></font></td>
</tr>
<tr>
<td align="center" colspan="2"><a href="#schrijf">Schrijf wat in het gastenboek</a></td>
</tr> <br>
<!-- bericht schrijven -->
<?php
$datum=getdate();
$dag = $datum['mday'];
$maand = $datum['mon'];
$jaar = $datum['year'];
$uur = $datum['hours'];
$min = $datum['minutes'];
$datumnu = "".$dag."-".$maand."-".$jaar." [".$uur.":".$min."]";
$haalberichten = mysql_query("SELECT van, datum, email, website, bericht FROM gastenboek ORDER by id DESC");
while($msg=mysql_fetch_object($haalberichten)){?>
<table cellspacing="0" width="300px"><tr>
<td align="right" width="20%"><b>Van:</b></td>
<td><?=$msg->van;?></td>
</tr>
<tr>
<td align="right"><b>op:</b></td>
<td><?=$msg->datum;?></td>
</tr>
<?
if($msg->email!=""){
?>
<tr><td align="right"><b>Email:</b></td>
<td><a href="mailto:<?=$msg->email;?>"><?=$msg->email;?></a></td></tr>
<? };
if($msg->website!=""){
?>
<tr><td align="right"><b>Website:</b></td>
<td><a href=<?=$msg->website;?> target="_blank"><?=$msg->website;?></a></td></tr>
<? };?>
<tr>
<td colspan="2" style="padding-left:10px;"><?=nl2br(htmlentities($msg->bericht));?></td>
</tr></table>
<?php
}
?>
</table>
<form name="schrijf" action="<?=$_SERVER['PHP_SELF'];?>?post=1" method="post">
<input type="hidden" name="datum" value="<?=$datumnu;?>" />
<table cellspacing="0" width="300px" id="schrijf">
<tr>
<td colspan="2" align="center"><font class="header">Schrijf in het gastenboek</font></td>
</tr>
<?=$error;?>
<tr>
<td width="50%">Naam:</td>
<td><input type="text" maxlength="255" name="naam" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" maxlength="255" name="email" /></td>
</tr>
<tr>
<td>Website:</td>
<td><input type="text" maxlength="255" name="website" value="http://" /></td>
</tr>
<tr>
<td colspan="2">Bericht:</td>
</tr>
<tr>
<td colspan="2" align="center">
<textarea name="bericht" cols="30" rows="5" class="textarea"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" class="submit" value="Post bericht" /></td>
</tr>
</table>
</form>
<a href="admin.php">Admin</a>
</center>
</body>
</html>
<? include"config.php"; $ip = $_SERVER['REMOTE_ADDR']; $error = ""; if(isset($_GET['post'])and ($_GET['post']=="1")){ if(empty($_POST['naam'])){ $error .= "<tr><td colspan=\"2\"><font color=\"red\">Geen naam ingevuld</font></td></tr>";} if(empty($_POST['naam'])){ $error .= "<tr><td colspan=\"2\"><font color=\"red\">Geen bericht ingevuld</font></td></tr>";} if(!empty($_POST['naam'])and (!empty($_POST['bericht']))){ $insert = "INSERT INTO gastenboek (van, datum, email, website, bericht, ip) VALUES ('".$_POST['naam']."', '".$_POST['datum']."', '".$_POST['email']."', '".$_POST['website']."', '".$_POST['bericht']."', '".$ip."')"; $error = "<tr><td colspan=\"2\" align=\"center\"><font color=\"green\">Alles is correct ingevuld</font></td></tr>"; } } } ?> <html> <head> <link href="style.css" rel="stylesheet" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Gastenboek</title> </head> <body> <center> <!-- gastenboek zelf --> <table cellspacing="0" width="300px"> <tr> <td colspan="2" align="center"><font class="header">Gastenboek</font></td> </tr> <tr> <td colspan="2" align="center"><font class="header">Aantal berichten:<?=$haalaantal;?></font></td> </tr> <tr> <td align="center" colspan="2"><a href="#schrijf">Schrijf wat in het gastenboek</a></td> </tr> <br> <!-- bericht schrijven --> <?php $dag = $datum['mday']; $maand = $datum['mon']; $jaar = $datum['year']; $uur = $datum['hours']; $min = $datum['minutes']; $datumnu = "".$dag."-".$maand."-".$jaar." [".$uur.":".$min."]"; $haalberichten = mysql_query("SELECT van, datum, email, website, bericht FROM gastenboek ORDER by id DESC"); <table cellspacing="0" width="300px"><tr> <td align="right" width="20%"><b>Van:</b></td> <td><?=$msg->van;?></td> </tr> <tr> <td align="right"><b>op:</b></td> <td><?=$msg->datum;?></td> </tr> <? if($msg->email!=""){ ?> <tr><td align="right"><b>Email:</b></td> <td><a href="mailto:<?=$msg->email;?>"><?=$msg->email;?></a></td></tr> <? }; if($msg->website!=""){ ?> <tr><td align="right"><b>Website:</b></td> <td><a href=<?=$msg->website;?> target="_blank"><?=$msg->website;?></a></td></tr> <? };?> <tr> <td colspan="2" style="padding-left:10px;"> <?=nl2br(htmlentities($msg->bericht));? ></td> </tr></table> <?php } ?> </table> <form name="schrijf" action="<?=$_SERVER['PHP_SELF'];?>?post=1" method="post"> <input type="hidden" name="datum" value="<?=$datumnu;?>" /> <table cellspacing="0" width="300px" id="schrijf"> <tr> <td colspan="2" align="center"><font class="header">Schrijf in het gastenboek</font></td> </tr> <?=$error;?> <tr> <td width="50%">Naam:</td> <td><input type="text" maxlength="255" name="naam" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" maxlength="255" name="email" /></td> </tr> <tr> <td>Website:</td> <td><input type="text" maxlength="255" name="website" value="http://" /></td> </tr> <tr> <td colspan="2">Bericht:</td> </tr> <tr> <td colspan="2" align="center"> <textarea name="bericht" cols="30" rows="5" class="textarea"></textarea> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" class="submit" value="Post bericht" /></td> </tr> </table> </form> <a href="admin.php">Admin</a> </center> </body> </html>
<---------------------->
Config.php
<---------------------->
<?php
$adminnaam = "Admin";
$adminwachtwoord = "******";
mysql_connect("localhost","root","******");
mysql_select_db("gastenboek");
// ipblocker
$ip = $_SERVER['REMOTE_ADDR'];
$blockedip = array(); // vb array("127.000.000.1","192.168.2.1")
if(in_array($ip,$blockedip)){
echo "Je bent geblocked, de reden zul je zelf wel weten!";
}
?>
<?php $adminnaam = "Admin"; $adminwachtwoord = "******"; // ipblocker $ip = $_SERVER['REMOTE_ADDR']; $blockedip = array(); // vb array("127.000.000.1","192.168.2.1") echo "Je bent geblocked, de reden zul je zelf wel weten!"; } ?>
<------------------->
Style.css
<------------------->
/* CSS Document */
BODY
{
background-color:#0099FF;
}
TABLE
{
border-color:#FF9900;
border-style:double;
background-color:#EEEEFF;
}
.header
{
color:#FF9900;
font-size:18px;
font-weight:bold;
}
.nonheader
{
color:#000000;
font-size:18px;
}
A
{color:#FF9900;
text-decoration:none;
background-color:#EEEEFF;
font-weight:bold;
}
A:hover
{
text-decoration:underline;
}
INPUT
{
background-color:#FF9900;
border:1;
font-style:italic;
}
.submit
{
background-color:#FF9900;
border-width:medium;
border-color:#000000;
font-style:normal;
font-weight:bold;
}
.textarea
{
background-color:#FF9900;
text-align:left;
border:0;
elevation:below;
}
/* CSS Document */ BODY { background-color:#0099FF; } TABLE { border-color:#FF9900; border-style:double; background-color:#EEEEFF; } { color:#FF9900; font-size:18px; font-weight:bold; } .nonheader { color:#000000; font-size:18px; } A {color:#FF9900; text-decoration:none; background-color:#EEEEFF; font-weight:bold; } A:hover { text-decoration:underline; } INPUT { background-color:#FF9900; border:1; font-style:italic; } .submit { background-color:#FF9900; border-width:medium; border-color:#000000; font-style:normal; font-weight:bold; } .textarea { background-color:#FF9900; text-align:left; border:0; elevation:below; }
<--------------->
Admin.php
<--------------->
<?php
ob_start();
include "config.php";
?>
<head>
<title>Gastenboek Admin</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<center>
<?php
if(isset($_GET['verwijder'])){
$delete = "DELETE FROM gastenboek WHERE id='".$_GET['verwijder']."'";
if(mysql_query($delete)){
?>
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Verwijderd</td>
</tr>
<tr>
<td width="50%" align="center">Het bericht is verwijderd.<br /><a href="admin.php?controleer=ja">Klik hier om terug te gaan</a></td>
</tr>
</table>
<?
exit();
}
else{
?>
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Niet verwijderd</td>
</tr>
<tr>
<td width="50%" align="center">Het bericht is niet verwijderd.<br /><a href="admin.php?controleer=ja">Klik hier om terug te gaan</a></td>
</tr>
</table>
<?
exit();
}
}
// de admin controleren
if(isset($_GET['controleer'])and($_GET['controleer']=="ja")){
if((isset($_POST['adminnaam']))and(isset($_POST['password']))){
if(($_POST['adminnaam']!=$adminnaam)or($_POST['password']!=$adminwachtwoord)){
?>
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Admin loginfout</td>
</tr>
<tr>
<td width="50%" align="center">Je kon niet worden ingelogd omdat er een fout was in je naam of wachtwoord<br /><a href="admin.php">Klik hier om het nogmaals te proberen</a></td>
</tr>
</table>
<?
exit();
}
if(($_POST['adminnaam']==$adminnaam)and($_POST['password']==$adminwachtwoord)){
setcookie("admingastenboek",$adminnaam,"0","/");
header("refresh:1");
}
}
if(isset($_COOKIE['admingastenboek'])){
$aantal = mysql_num_rows(mysql_query("SELECT * FROM gastenboek"));
if($aantal>0){
$select = mysql_query("SELECT id, van, datum, email, website, bericht, ip FROM gastenboek ORDER by id DESC");
?>
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Gastenboek Admin</td>
</tr>
<tr>
<? while($f=mysql_fetch_object($select)){?>
<table width="300px">
<tr>
<td class="header" width="20%" align="right">ID:</td>
<td class="nonheader"><?=$f->id;?></td>
</tr>
<tr>
<td class="header" align="right">Van:</td>
<td class="nonheader"><?=$f->van;?></td>
</tr>
<tr>
<td class="header" align="right">op:</td>
<td class="nonheader"><?=$f->datum;?></td>
</tr>
<tr>
<td class="header" align="right">email:</td>
<td class="nonheader"><?=$f->email;?></td>
</tr>
<tr>
<td class="header" align="right">Website:</td>
<td class="nonheader"><a href="http://<?=$f->website;?>"><?=$f->website;?></a></td>
</tr>
<tr>
<td class="header" align="right">IP:</td>
<td class="nonheader"><a href="http://network-tools.com/default.asp?host=<?=$f->ip;?>" target="_blank"><?=$f->ip;?></a></td>
</tr>
<tr>
<td class="header" align="right" valign="top">bericht:</td>
<td class="nonheader"><?=$f->bericht;?></td>
</tr>
<tr height="20">
<td></td>
</tr>
<tr>
<td class="nonheader" colspan="2"><a href="<?=$_SERVER['PHP_SELF'];?>?delete=<?=$f->id;?>">Verwijder</a></td>
</tr>
</table>
<?php }?>
</table>
<?php
}
else{?>
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Gastenboek Admin</td>
</tr>
<tr>
<td class="nonheader" align="center">Geen berichten</td>
</tr>
</table>
<?php
}
exit();
}
}
if(isset($_GET['delete'])){
if(!isset($_COOKIE['admingastenboek'])){
echo"Je moet wel ingelogd zijn";
exit();
}
if(isset($_COOKIE['admingastenboek'])){
$haalop=mysql_fetch_object(mysql_query("SELECT van, datum, ip FROM gastenboek"));?>
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Gastenboek Admin</td>
</tr>
<tr> <td class="nonheader" align="center">Weet u zeker dat u het bericht van <?=$haalop->van;?>,<br />gepost op: <?=$haalop->datum;?><br />Vanaf IP: <?=$haalop->ip;?>,<br />wilt verwijderen?</td>
</tr>
</table>
<table width="300px" cellspacing="0">
<tr>
<td width="50%" align="center"><a href="<?=$_SERVER['PHP_SELF'];?>?verwijder=<?=$_GET['delete'];?>">Ja</a></td>
<td align="center"><a href="<?=$_SERVER['PHP_SELF'];?>?controleer=ja">Nee</a></td>
</tr>
</table>
<?
exit();
}
}
if(isset($_COOKIE['admingastenboek'])){
header("location:admin.php?controleer=ja");
}
?>
<!-- Het loginscherm -->
<form name="adminlogin" action="<?=$_SERVER['PHP_SELF'];?>?controleer=ja" method="post">
<table width="300px" cellspacing="0">
<tr>
<td colspan="2" class="header" align="center">Admin Login</td>
</tr>
<tr>
<td class="header" width="50%">Naam:</td>
<td class="header"><input type="text" name="adminnaam" /></td>
</tr>
<tr>
<td class="header">Wachtwoord:</td>
<td class="header"><input type="password" name="password" /></td>
</tr>
<tr>
<td class="header" colspan="2" align="center"><input type="submit" value="Controleer" class="submit" /></td>
</tr>
</table>
</form>
</center>
</body>
<?php include "config.php"; ?> <head> <title>Gastenboek Admin</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <center> <?php if(isset($_GET['verwijder'])){ $delete = "DELETE FROM gastenboek WHERE id='".$_GET['verwijder']."'"; ?> <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Verwijderd</td> </tr> <tr> <td width="50%" align="center">Het bericht is verwijderd.<br /><a href="admin.php?controleer=ja">Klik hier om terug te gaan</a></td> </tr> </table> <? } else{ ?> <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Niet verwijderd</td> </tr> <tr> <td width="50%" align="center">Het bericht is niet verwijderd.<br /><a href="admin.php?controleer=ja">Klik hier om terug te gaan</a></td> </tr> </table> <? } } // de admin controleren if(isset($_GET['controleer'])and ($_GET['controleer']=="ja")){ if((isset($_POST['adminnaam']))and (isset($_POST['password']))){ if(($_POST['adminnaam']!=$adminnaam)or($_POST['password']!=$adminwachtwoord)){ ?> <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Admin loginfout</td> </tr> <tr> <td width="50%" align="center">Je kon niet worden ingelogd omdat er een fout was in je naam of wachtwoord<br /><a href="admin.php">Klik hier om het nogmaals te proberen</a></td> </tr> </table> <? } if(($_POST['adminnaam']==$adminnaam)and($_POST['password']==$adminwachtwoord)){ setcookie("admingastenboek",$adminnaam,"0","/"); } } if(isset($_COOKIE['admingastenboek'])){ if($aantal>0){ $select = mysql_query("SELECT id, van, datum, email, website, bericht, ip FROM gastenboek ORDER by id DESC"); ?> <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Gastenboek Admin</td> </tr> <tr> <table width="300px"> <tr> <td class="header" width="20%" align="right">ID:</td> <td class="nonheader"><?=$f->id;?></td> </tr> <tr> <td class="header" align="right">Van:</td> <td class="nonheader"><?=$f->van;?></td> </tr> <tr> <td class="header" align="right">op:</td> <td class="nonheader"><?=$f->datum;?></td> </tr> <tr> <td class="header" align="right">email:</td> <td class="nonheader"><?=$f->email;?></td> </tr> <tr> <td class="header" align="right">Website:</td> <td class="nonheader"><a href="http://<?=$f->website;?>"><?=$f->website;?></a></td> </tr> <tr> <td class="header" align="right">IP:</td> <td class="nonheader"><a href="http://network-tools.com/default.asp?host=<?=$f->ip;?>" target="_blank"><?=$f->ip;?></a></td> </tr> <tr> <td class="header" align="right" valign="top">bericht:</td> <td class="nonheader"><?=$f->bericht;?></td> </tr> <tr height="20"> <td></td> </tr> <tr> <td class="nonheader" colspan="2"><a href="<?=$_SERVER['PHP_SELF'];?>?delete=<?=$f->id;?>">Verwijder</a></td> </tr> </table> <?php }?> </table> <?php } else{?> <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Gastenboek Admin</td> </tr> <tr> <td class="nonheader" align="center">Geen berichten</td> </tr> </table> <?php } } } if(isset($_GET['delete'])){ if(!isset($_COOKIE['admingastenboek'])){ echo"Je moet wel ingelogd zijn"; } if(isset($_COOKIE['admingastenboek'])){ <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Gastenboek Admin</td> </tr> <tr> <td class="nonheader" align="center">Weet u zeker dat u het bericht van <?=$haalop->van;?>,<br />gepost op: <?=$haalop->datum;?><br />Vanaf IP: <?=$haalop->ip;?>,<br />wilt verwijderen?</td> </tr> </table> <table width="300px" cellspacing="0"> <tr> <td width="50%" align="center"><a href="<?=$_SERVER['PHP_SELF'];?>?verwijder=<?=$_GET['delete'];?>">Ja</a></td> <td align="center"><a href="<?=$_SERVER['PHP_SELF'];?>?controleer=ja">Nee</a></td> </tr> </table> <? } } if(isset($_COOKIE['admingastenboek'])){ header("location:admin.php?controleer=ja"); } ?> <!-- Het loginscherm --> <form name="adminlogin" action="<?=$_SERVER['PHP_SELF'];?>?controleer=ja" method="post"> <table width="300px" cellspacing="0"> <tr> <td colspan="2" class="header" align="center">Admin Login</td> </tr> <tr> <td class="header" width="50%">Naam:</td> <td class="header"><input type="text" name="adminnaam" /></td> </tr> <tr> <td class="header">Wachtwoord:</td> <td class="header"><input type="password" name="password" /></td> </tr> <tr> <td class="header" colspan="2" align="center"><input type="submit" value="Controleer" class="submit" /></td> </tr> </table> </form> </center> </body>
Download code (.txt)
|
|
|
Stemmen |
Niet ingelogd. |
|