1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Livre d'or</title>
<link href="guestbook.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
</head>
<body>
<?php
//Définition des variables et de leurs valeurs à null
$auteur= $ville = $email= $website= $message= $evaluation= $ip= $datesoumission= "";
$auteurErr= $villeErr = $emailErr= $websiteErr= $evaluationErr= $messageErr="";
//Recherche d'ip d'utilisateur
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
//Capture de l'heure de soumission
date_default_timezone_set('Europe/Paris');
$datesoumission= Date('d/m/Y H:i:s');
//Fonction
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//Contrôle des champs et valeurs de champs
if(isset($_REQUEST['Envoyer'])){
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (empty($_POST["auteur"])) {
$auteurErr = "Votre nom ou pseudo est obligatoire";
}
else
{
$auteur = test_input($_POST["auteur"]);
if (!preg_match("/^[a-zA-Z ]*$/",$auteur)) {
$auteurErr = "Seuls des lettres et espaces sont acceptés dans ce champ";
}
}
if (empty($_POST["ville"])) {
$villeErr = "Veuillez indiquer votre ville.";
}
else
{
$ville = test_input($_POST["ville"]);
}
if (empty($_POST["email"])) {
$emailErr = "Veuillez renseigner votre adresse mail";
}
else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Format de mail invalide";
}
}
$website = test_input($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Adresse internet invalide, veuillez vérifiez son format";
}
if (empty($_POST["message"])) {
$messageErr = "Vous devez entrer un commentaire ou message";
}
else {
$message = test_input($_POST["message"]);
}
if ($_POST["evaluation"]== "Aucune") {
$evaluationErr = "Vous devez entrer une évaluation globale";
}
else {
$evaluation = test_input($_POST["evaluation"]);
}
}
$xml= new DOMDocument("1.0","UTF-8");
$xml->preserveWhiteSpace = false;
$xml->load("guestbook.xml");
$rootTag=$xml->getElementsByTagName("guestbook")->item(0);
$dataTag=$xml->createElement("data");
$auteurTag=$xml->createElement("auteur",$_REQUEST['auteur']);
$villeTag=$xml->createElement("ville",$_REQUEST['ville']);
$emailTag=$xml->createElement("email",$_REQUEST['email']);
$websiteTag=$xml->createElement("website",$_REQUEST['website']);
$messageTag=$xml->createElement("message",$_REQUEST['message']);
$evaluationTag=$xml->createElement("evaluation",$_REQUEST['evaluation']);
$datesoumissionTag=$xml->createElement("datesoumission","$datesoumission");
$ipTag=$xml->createElement("ip","$ip");
$dataTag->appendChild($auteurTag);
$dataTag->appendChild($villeTag);
$dataTag->appendChild($emailTag);
$dataTag->appendChild($websiteTag);
$dataTag->appendChild($messageTag);
$dataTag->appendChild($evaluationTag);
$dataTag->appendChild($datesoumissionTag);
$dataTag->appendChild($ipTag);
$rootTag->appendChild($dataTag);
$xml->save("guestbook.xml");
}
?>
<div id="Container">
<form method="post" action="guestbook.php" >
<table style="width: 100%">
<tr>
<td style="width: 175px"> </td>
<td style="width: 381px">
<input name="DateSoumission1" type="text" disabled= "disabled" value="<?php echo $datesoumission;?>" size="20"/></td>
<td>
</td>
</tr>
<tr>
<td style="width: 175px"><label id="Label5" class="Etiquette">Nom ou pseudo :</label></td>
<td style="width: 381px">
<input type= "text" name= "auteur" style="width: 368px" value="<?php echo $ville;?>"/></td>
<td>
<span class="error">* <?php echo $auteurErr;?></span>
</td>
</tr>
<tr>
<td style="width: 175px"><label id="Label1"class="Etiquette">Ville</label></td>
<td style="width: 381px">
<input type= "text" name= "ville"style="width: 368px" value="<?php echo $ville;?>"/></td>
<td><span class="error">* <?php echo $villeErr;?></span>
</td>
</tr>
<tr>
<td style="width: 175px"><label id="Label2"class="Etiquette">Email</label></td>
<td style="width: 381px">
<input type= "text" name= "email"style="width: 368px" value="<?php echo $email;?>"/></td>
<td><span class="error">* <?php echo $emailErr;?></span></td>
</tr>
<tr>
<td style="width: 175px"><label id="Label3"class="Etiquette">Website</label></td>
<td style="width: 381px">
<input type= "text" name= "website"style="width: 368px" value="<?php echo $website;?>"/></td>
<td><span class="error">* <?php echo $websiteErr;?></span></td>
</tr>
<tr>
<td style="width: 175px"><label id="Label6"class="Etiquette">Evaluation globale :</label></td>
<td style="width: 381px">
<select name="evaluation" style="width: 368px">
<option value="Aucune">Aucune</option>
<option value="Excellent">Excellent</option>
<option value="Très bien">Très bien</option>
<option value="Bien">Bien</option>
<option value="Passable">Passable</option>
<option value="Médiocre">Médiocre</option>
<option value="Très Mauvais">Très mauvais</option>
<?php echo $evaluation ?></select>
</td>
<td><span class="error">* <?php echo $evaluationErr;?></span></td>
</tr>
<tr>
<td style="width: 175px"><label id="Label4"class="Etiquette">Message ou commentaire :</label></td>
<td style="width: 381px">
<textarea name= "message" cols="20" rows= "10" style = "width: 368px"><?php echo $message;?></textarea></td>
<td>
<span class="error">* <?php echo $messageErr;?></span>
</td>
</tr>
<tr>
<td style="width: 175px"></td>
<td style="width: 381px">
</td>
<td>
</td>
</tr>
<tr>
<td style="width: 175px; height: 26px;"><label id="Label7">Votre adresse Ip est :</label></td>
<td style="width: 381px; height: 26px;">
<input name="AdresseIp" disabled="disabled"value="<?php echo $ip; ?>" style="width: 88px"/></td>
<td style="height: 26px"> </td>
</tr>
<tr>
<td style="width: 175px; height: 26px;"> </td>
<td style="width: 381px; height: 26px;">
<input type="submit" name="Envoyer" value= "Envoyer" title="Envoyer"/></td>
<td style="height: 26px">
</td>
</tr>
</table>
</form>
</div><!--Fin de div Container--!>
</body>
</html> |
Partager