<? // Exemple de GuestBook v10pm
// Paramètres de connexion
$host = "localhost"; // "mysql.nexen.net" chez Nexen
$user = "root"; // ou vide en local
$pass = ""; // vide en local
$bdd = "ma_base"; // nom de la BD
// connexion
@mysql_connect($host,$user,$pass)
or die("Impossible de se connecter");
@mysql_select_db("$bdd")
or die("Impossible de se connecter");
$table="guestbook";
$URL = $PHP_SELF;
$fond="#DDDDFF"; $zone = "#EEEEFF";
// Ecriture du nouveau message
if($comment) {
$date = time();
$query = "INSERT INTO $table(date,name,email,url,city,country,comment)";
$query .= " VALUES('$date','$name','$email','$url','$city','$country','$comment')";
$result = mysql_query($query);
}
// Vérif mot de passe admin
if($passe=="toto") {
setcookie("guestbook","ok");
Header("Location: $URL");
}
// Sortie du mode admin
if($act=="noadmin") {
setcookie("guestbook");
Header("Location: $URL");
}
// Destruction d'un message indésirable
if(isset($del) && isset($guestbook)) {
$query = "DELETE FROM $table WHERE date = '$del'";
$result = mysql_query($query);
}
?>
<HTML><HEAD><TITLE>Mon Livre d'Or</TITLE>
<style type="text/css"><!--
A { font:bold 8pt Verdana }
:hover { color:red;text-decoration:overline }
td,th,textarea,input { font:normal 8pt Verdana }
.titre { background:<? echo $fond; ?> }
--></style>
</HEAD><BODY bgcolor="<? echo $fond; ?>">
<table width=100% height=100% bgcolor="<? echo $zone; ?>"><tr><th>
<? if($act=="admin") { ?>
<form method="post" action="<? echo $URL; ?>">
<table><tr>
<th>Mot de passe : </th>
<th><input type="password" name="passe" size=10></input></th>
<th><input type="Submit" value="OK"></input></th>
</tr></table>
</form>
<? } else { ?>
<A href="#form">Signez mon Livre d'Or !</A><br>
<? $query = "SELECT * FROM $table ORDER BY date DESC";
$result = mysql_query($query);
echo mysql_numrows($result); ?> messages
<? if($guestbook) { ?>
<br><A href="<? echo $URL; ?>?act=noadmin">Sortir du mode admin</A>
<? } ?>
<table width=95%><tr><td><hr size=1>
<? while ($val = mysql_fetch_array($result)) { ?>
<div class=titre><? if($guestbook) { ?>
<A href="<? echo $URL; ?>?del=<? echo $val["date"]; ?>">
<img src="minipoub.gif" border=0 width=14 height=15 align="absmiddle"></A>
<? } ?>
<? echo date("d/m/Y",$val["date"]); ?>
de <A href="mailto:<? echo $val["email"]; ?>"><? echo $val["name"]; ?></A>
(<? echo $val["city"]; ?>,&nbsp;<? echo $val["country"]; ?>)</div>
<? if($val["url"]!="") { ?>
<A href="<? echo $val["url"]; ?>" target="_blank"><? echo $val["url"]; ?></A>
<? } ?>
<div><? echo str_replace("<","&lt;",$val["comment"]); ?></div><hr size=1>
<? } ?>
</td></tr></table>
<script language="JavaScript"><!--
function verif(email) {
var arobase = email.indexOf("@"); var point = email.lastIndexOf(".")
if((arobase < 3)||(point + 2 > email.length)||(point < arobase+3)) return false
return true
}
function testform(nom,mail,url,city,country,comment) {
if(nom.value=="") { nom.focus();return false }
if(!verif(mail.value)) { mail.value="";mail.focus();return false }
if(url.value=="http://") { url.value="" }
if(city.value=="") { city.focus();return false }
if(country.value=="") { country.focus();return false }
if(comment.value=="") { comment.focus();return false }
return true
}
//--></script>
<A name="form"></A><table width=80%><tr><th>
<form method="post" action="<? echo $URL; ?>"
onSubmit="return testform(this.name,this.email,this.url,this.city
,this.country,this.comment)">
<table cellspacing=0 cellpadding=3 border=0 bgcolor="<? echo $fond; ?>"><tr>
<th colspan=4>Nom<br><input name="name" size=15></th>
<th colspan=4>Ville<br><input name="city" size=15></th>
<th colspan=4>Pays<br><input name="country" size=15></th>
</tr><tr>
<th>&nbsp;</th>
<th colspan=5>E-mail<br><input name="email" size=20></th>
<th colspan=5>Site<br><input name="url" value="http://" size=20>
</th><th>&nbsp;</th>
</tr><tr>
<th colspan=12><br><textarea name="comment" rows=4 cols=55></textarea>
<br><br><input type="Submit" value="Signer ce Livre d'Or"></input><br>
<br><A href="#">Haut de la page</A><br><br>
</th></tr></table>
</form>
</table>
<? } ?>
</th></tr></table>
</BODY></HTML>
<? mysql_close(); ?>