Bonsoir à tous,

Je suis débute en PHP , je me suis lancé dans le projet de faire un topsite , mon presque est pratiquement terminé , il me manque juste la sécurité du vote -->

Le système : L'internaute peut voter pour un topsite , par cookie et par ip toutes les 2 heures , avec l'ip pas grand problème

je retiens l'adresse ip dans ma base avec la dateheure , l'id du topsite , et je vérifie si l'écart écoulé entre la date si elle présente

dans la base , si oui l'écart doit-être plus de 2 heures pour voter à nouveau ... Bon bref ... faire un système de vote sécurisé

par ip et cookie

Voilà mon script actuelle ( qui est vraiment mal construit )

Si vous pouvez m'aider sa serais pas mal , merci d'avance à tous ....

Le script

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
 
<html>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
	<?php include('includes/head.inc.php'); ?>
</head>
<body id="bd" class=" wide fs3" style="background-image: url(templates/ja_sanidine/images/background/gaming.jpg);" >
 
	<?php include('includes/header.inc.php'); ?>
 
	<!-- BEGIN: MAIN NAVIGATION -->
 
	<?php include('includes/menu.inc.php'); ?>
	<!-- END: MAIN NAVIGATION -->
	<?php
 
	$name=null;
 
// Recuperation du nom du serveur + clef dans l'url 
	$url =mysql_real_escape_string($_GET['site']);
 
	?>
	<div id="ja-subnav" class="clearfix">
		<div class="sublevel">
			<ul><li><a href="viewserv.php?site=<?php echo $url; ?>" class=" active" class=" first-item" id="menu59" title="Wrapper (full width)"><span class="menu-title">Présentation</span></a></li><li ><a href="index5fe2.html?option=com_content&amp;view=article&amp;id=24&amp;Itemid=73" id="menu73" title="Content + Right column"><span class="menu-title">Avis</span></a></li><li class=" active"><a href="voteserv.php?site=<?php echo $url;?>"  style="color:red;" id="menu70" title="Without extra modules"><span class="menu-title">Voter</span></a></li><li ><a href="index6746.html?option=com_content&amp;view=article&amp;id=23&amp;Itemid=60"  id="menu60" title="Content + Left Column"><span class="menu-title">Statistiques</span></a></li></ul>
		</div></div>
 
		<?php
 
 
 
 
// Connexion à ma base de donnéess
 
		$base = mysql_connect (''.$host.'', ''.$username.'', ''.$pass.'');
		mysql_select_db (''.$db.'', $base);
 
 
 
		$resultat = mysql_query("select * FROM top WHERE rewr= '$url'");
		while($ligne = mysql_fetch_array($resultat)){
			$serv_id=$ligne['id'];
			$name=$ligne['name'];
			$text=$ligne['text'];
			$web=$ligne['web'];
			$point=$ligne['point'];
			$game=$ligne['game'];
			$video_id=$ligne['video'];
			$logo=$ligne['logo'];
		}
 
 
		?>
 
		<div id="ja-containerwrap-fl">
			<div id="ja-container" class="clearfix">
 
				<div id="ja-mainbody" class="clearfix">
 
 
					<!-- BEGIN: CONTENT -->
					<div id="ja-content"><div id="ja-content-top"><div id="ja-content-bot" class="clearfix">
 
 
						<div id="ja-current-content" class="clearfix">
 
							<h2 class="contentheading">
								<?php echo reduireChaineCar(htmlentities(strip_tags($name)), 45);?></h2>
 
 
 
 
								<div class="article-content">
 
 
 
									<?php
	// Définition de la fonction reduction du texte
									function reduireChaineCar($chaine, $nb_car, $delim='...') 
									{
										$length = $nb_car;
										if($nb_car<strlen($chaine)){
											while (($chaine{$length} != " ") && ($length > 0)) {
												$length--;
											}
											if ($length == 0) return substr($chaine, 0, $nb_car) . $delim;
											else return substr($chaine, 0, $length) . $delim;
										}else return $chaine;
									}
 
 
									$name=null;
 
 
									$base = mysql_connect (''.$host.'', ''.$username.'', ''.$pass.'');
									mysql_select_db (''.$db.'', $base);
 
// Recuperation du nom du serveur + clef dans l'url 
									$url =mysql_real_escape_string($_GET['site']);
 
 
									$resultat = mysql_query("select * FROM top WHERE rewr= '$url'");
									while($ligne = mysql_fetch_array($resultat)){
										$annonce=$ligne['annonce'];
										$serv_id=$ligne['id'];
										$name=$ligne['name'];
										$text=$ligne['text'];
										$web=$ligne['web'];
										$point=$ligne['point'];
										$game=$ligne['game'];
										$logo=$ligne['logo'];
										$video_id=$ligne['video'];
										$clic=$ligne['nb_clic'];
										$url=$ligne['rewr'];
									}
 
 
									?>
 
 
									<h3>Complétez le captcha suivant pour voter</h3>
 
 
									<form action="voteserv.php?site=<?php echo $url; ?>" method="post">
 
										<?php
///// Script Affichage captcha //////
require_once('recaptcha/recaptchalib.php'); // Vérifier que l'URL relative correspond à l'emplacement du fichier (adapter si nécessaire)
$publickey = "6Lc4we8SAAAAAMYdIgmnt570cJemgAtBYn4tiW_A"; // Utiliser la clé que vous avez eu lors de l'inscription sur recaptcha.net
echo recaptcha_get_html($publickey); // Affiche le captcha
?>
 
<input style="margin-top:20px;" type="submit" name="submit" value="Valider le captcha">
 
</form>
 
<?php
 
 
// Message erreur vote
$erreur_msg_vote='Vous avez déjà voter ';
 
if (isset($_POST['submit']))
 
{
 
if(isset($_COOKIE["time"])){
    setcookie("time",$serv_id, time()+7200); 
}else{
 
}
 
 
/////// Script validation captcha /////
	$privatekey = "6Lc4we8SAAAAADPpcYcxFLHbPa_NO8X_5dpnnIVZ"; 
	// Utiliser la clé privée qui est donnée sur votre compte recaptcha.net
	$resp = recaptcha_check_answer ($privatekey,
		$_SERVER["REMOTE_ADDR"],
		$_POST["recaptcha_challenge_field"],
		$_POST["recaptcha_response_field"]);
 
	if (!$resp->is_valid) 
 
	{ 
 
  // Test si le captcha a bien été rempli
  // Si le captcha n'est pas valide
		echo '<br><font color="red"><strong>Le captcha est incorrecte .</strong></font>';
 
	}
	else
 
	{
// Récupération de l'adresse IP du visiteur
 
		$guest_ip = $_SERVER['REMOTE_ADDR'];
 
// Récupération Date / Heure actuelle
 
		$datedevote=date('Y-m-d G:i:s'); 
 
// Vérifie si l'adresse IP est déjà présente dans la base
 
		$req = mysql_query("SELECT ip FROM vote WHERE ip = '" . $guest_ip . "' AND guid ='$serv_id' ") or exit(mysql_error());
 
// Date heure du dernier vote
 
		$resultat = mysql_query("SELECT * FROM vote WHERE ip = '" . $guest_ip . "'  AND guid ='$serv_id' ") or exit(mysql_error());
 
		while($ligne = mysql_fetch_array($resultat))
		{
			$datedevotelast=$ligne['dateheure'];
		}
 
 
		if (mysql_num_rows($req) == 1 && $_COOKIE['time'] == $serv_id) 
		{
 
//// Fonction qui calcule l'écart entre 2 votes ////
 
 
			$date1 = $datedevote;
 
			$date2 = $datedevotelast;
 
			$time1 = strtotime($date1);
			$time2 = strtotime($date2);
			if( $time1 > $time2 ) {
				$time = $time1 - $time2;
			} else {
				$time = $time2 - $time1;
			}
 
			$time = $time / 3600 * 3600 ;
 
			if ($time>=7200)
			{
 
// Carte au trésor Partie 1 
				$partone=1; 
 
// lancement SQL
				$sql = "UPDATE vote SET dateheure = '$datedevote'  WHERE ip = '$guest_ip'  AND guid ='$serv_id' ";
 
// Erreur si SQL fonctionne pas
 
				mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error());
			}
			else
			{
				echo 'Vous venez de voter , veuillez attendre --> ';
				echo $time;
				echo ' secondes';
			}
 
		}
 
 
		elseif (!mysql_num_rows($req)) 
		{
 
// Carte au trésor Partie 1 
			$partone=1; 
 
// lancement SQL
			$sql    = "INSERT INTO vote (ip,guid,dateheure) VALUES('$guest_ip','$serv_id','$datedevote')";
 
// Erreur si SQL fonctionne pas
			mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error());
 
 
 
		}
 
		elseif ($time<7200)
		{
 
			echo 'Vous venez de voter , veuillez attendre --> ';
			echo $time;
			echo ' secondes';
 
 
 
		}
 
	}
 
}
?>
 
</div>
 
 
 
<span class="article_separator">&nbsp;</span>
 
</div>
 
</div></div></div>
<!-- END: CONTENT -->
 
 
 
<!-- BEGIN: CONTENT SPOTLIGHT 2-->
<div id="ja-contentsl2" class="clearfix">	
 
	<div class="ja-box-left" style="width: 49.95%;">
		<div class="module">
			<div>
				<div>
					<div>
						<h3>World of Warcraft</h3>
						<img src="images/stories/demo/sam-8.jpg" alt="" />
 
						Maecenas nibh congue justo est adipiscing elit mauris orci lacus dui. <a href="#" title="Sample link">Read more</a>					</div>
					</div>
				</div>
			</div>
 
		</div>
 
		<div class="ja-box-right" style="width: 49.95%;">
			<div class="module">
				<div>
					<div>
						<div>
							<h3>Cross fire</h3>
							<img src="images/stories/demo/sam-9.jpg" alt="Sample image" />
 
							Ut Vestibulum semper Sed Sed sem dui convallis pretium morbi Nullam. <a href="#" title="Sample link">Read more</a>					</div>
						</div>
					</div>
				</div>
 
			</div>
 
		</div>
		<!-- END: CONTENT SPOTLIGHT 2-->
 
		<!-- BEGIN: TABS -->
		<div id="ja-tabs" class="clearfix">
 
		</div>
		<!-- END: TABS-->
 
	</div>
 
	<!-- BEGIN: RIGHT COLUMN -->
	<div id="ja-col2">
		<div class="ja-innerpad">
			<div class="module">
				<div>
					<div>
						<div>
							<h3>Informations</h3>
							<li class="latestnews">
								<a href="index8e76.html?option=com_content&amp;view=article&amp;id=85:light-and-dark&amp;catid=34:demo-category&amp;Itemid=78" class="latestnews">
									Position actuelle</a>
								</li>											
								<li class="latestnews">
									<a href="index8e76.html?option=com_content&amp;view=article&amp;id=85:light-and-dark&amp;catid=34:demo-category&amp;Itemid=78" class="latestnews">
										Nombre de votes -> <?php echo $point; ?></a>
									</li>
									<li class="latestnews">
										<a href="index8e76.html?option=com_content&amp;view=article&amp;id=85:light-and-dark&amp;catid=34:demo-category&amp;Itemid=78" class="latestnews">
											Intérêt -> <?php echo $clic; ?></a>
										</li>
										<li class="latestnews">
											<a href="index8e76.html?option=com_content&amp;view=article&amp;id=85:light-and-dark&amp;catid=34:demo-category&amp;Itemid=78" class="latestnews">
												Catégorie -> <?php echo $game; ?></a>
											</li>
											<?php if(isset($_SESSION['username'])) { ?>
											<li class="latestnews">
												<a style="color:purple;"href="index8e76.html?option=com_content&amp;view=article&amp;id=85:light-and-dark&amp;catid=34:demo-category&amp;Itemid=78" class="latestnews">
													Ajouter ce site dans mes favoris</a>
												</li>
												<?php }  ?>
 
											</div>
										</div>
									</div>
								</div>
								<div class="module">
									<div>
										<div>
											<div>
												<h3>Video Picks</h3>
												<div class="ja-innerdiv clearfix">
													<img src="images/stories/demo/sam-5.jpg" alt="Sample image" align="right" />
													<a href="#" title="Sample link"><strong>Adipiscing vitae</strong></a><br />
													Cursus Cum pellentesque Sed ante nulla vel. Et tincidunt Nulla vitae vel mauris quis porttitor.
												</div>
 
												<div class="ja-innerdiv clearfix">
													<img src="images/stories/demo/sam-6.jpg" alt="Sample image" align="right" />
													<a href="#" title="Sample link"><strong>A commodo Vesti</strong></a><br />
													Est congue pretium rhoncus mi In orci. Tincidunt non velit pellentesque.
												</div>
 
												<div class="ja-innerdiv clearfix">
													<img src="images/stories/demo/sam-7.jpg" alt="Sample image" align="right" />
													<a href="#" title="Sample link"><strong>Laoreet pretium</strong></a><br />
													Laoreet pretium tempus enim eu urna orci at ut pede sagittis.
												</div>					</div>
											</div>
										</div>
									</div>
									<div class="module_fixbr">
										<div>
											<div>
												<div>
													<h3>CB Gallery Module</h3>
													<div style="width:100%;margin:0px;padding:0px;border:0px;text-align:left;float:left;"><div style="border:0px solid;padding:5px 5px 20px;margin:1px;height:125px;width:100px;text-align:center;float:left;"><div style="height:125px;"><a href="index5c4c.html?option=com_comprofiler&amp;task=userProfile&amp;user=67&amp;tab=getProfileGalleryTab"><img src="images/comprofiler/plug_profilegallery/67/tnpg_117391204.jpg" border="0" height="125" width="95" title="The Forbiden Kingdom" alt="The Forbiden Kingdom" /></a></div><br /><div style="color:#666666; display: block;">[The Forbid...]</div><br /></div><div style="border:0px solid;padding:5px 5px 20px;margin:1px;height:125px;width:100px;text-align:center;float:left;"><div style="height:125px;"><a href="index52d2.html?option=com_comprofiler&amp;task=userProfile&amp;user=62&amp;tab=getProfileGalleryTab"><img src="images/comprofiler/plug_profilegallery/62/tnpg_1716137155.jpg" border="0" height="125" width="95" title="Fantasy Girl" alt="Fantasy Girl" /></a></div><br /><div style="color:#666666; display: block;">[Fantasy Gi...]</div><br /></div><div style="border:0px solid;padding:5px 5px 20px;margin:1px;height:125px;width:100px;text-align:center;float:left;"><div style="height:125px;"><a href="index6dc7.html?option=com_comprofiler&amp;task=userProfile&amp;user=68&amp;tab=getProfileGalleryTab"><img src="images/comprofiler/plug_profilegallery/68/tnpg_753717919.jpg" border="0" height="125" width="95" title="Moto" alt="Moto" /></a></div><br /><div style="color:#666666; display: block;">[Moto]</div><br /></div><div style="border:0px solid;padding:5px 5px 20px;margin:1px;height:125px;width:100px;text-align:center;float:left;"><div style="height:125px;"><a href="index52d2.html?option=com_comprofiler&amp;task=userProfile&amp;user=62&amp;tab=getProfileGalleryTab"><img src="images/comprofiler/plug_profilegallery/62/tnpg_1574874889.jpg" border="0" height="125" width="95" title="Fantasy " alt="Fantasy " /></a></div><br /><div style="color:#666666; display: block;">[Fantasy ]</div><br /></div></div><div style="clear:both; height:1px;" >&nbsp;</div>					</div>
												</div>
											</div>
										</div>
										<div class="module">
											<div>
												<div>
													<div>
														<h3>CB Online</h3>
														None					</div>
													</div>
												</div>
											</div>
 
										</div></div><br />
										<!-- END: RIGHT COLUMN -->
 
									</div></div>
 
 
 
									<?php include('includes/footer.inc.php'); ?>
 
								</body>
 
 
									</html>