Vot cu ajutorul PHP si CSS

Ca webmaster de multe ori ai nevoie de un sistem de vot pentru diferite rubrici din website, asa ca m-am gandit sa postez un script de vot simplu si usor de editat in functie de nevoi.

style.css

.star-rating {
	background: url(vot-cu-ajutorul-php-si-css-01.png) top left repeat-x; 
	margin: 5px; 
	padding: 0px;
	width: 150px;
	height: 30px;
	list-style: none;
	position: relative; 
}

.star-rating li {
	padding: 0px;
	margin: 0px; 
	float: left;
}

.star-rating li a {
	background-image: none; 
	width: 30px;
	height: 30px; 
	padding: 0px; 
	display: block;
	text-decoration: none; 
	text-indent: -9000px; 
	z-index: 30; 
	position: absolute; 
}

.star-rating li a:hover {
	background: url(vot-cu-ajutorul-php-si-css-01.png) left bottom; 
	z-index: 1; 
	left: 0px; 
}

.star-rating a.one-star {
	left: 0px;
}
.star-rating a.one-star:hover {
	width: 30px;
}

.star-rating a.two-stars {
	left: 30px;
}
.star-rating a.two-stars:hover {
	width: 60px;
}

.star-rating a.three-stars {
	left: 60px;
}
.star-rating a.three-stars:hover {
	width: 90px;
}

.star-rating a.four-stars {
	left: 90px;
}
.star-rating a.four-stars:hover {
	width: 120px;
}

.star-rating a.five-stars {
	left: 120px;
}
.star-rating a.five-stars:hover {
	width: 150px;
}

vot.html

<ul class="star-rating">
	<li><a href="/vot.php?vot=1" title="Votul tau: 1 punct din 5" class="one-star">1</a></li>
	<li><a href="/vot.php?vot=2" title="Votul tau: 2 puncte din 5" class="two-stars">2</a></li>
	<li><a href="/vot.php?vot=3" title="Votul tau: 3 puncte din 5" class="three-stars">3</a></li>
	<li><a href="/vot.php?vot=4" title="Votul tau: 4 puncte din 5" class="four-stars">4</a></li>
	<li><a href="/vot.php?vot=5" title="Votul tau: 5 puncte din 5" class="five-stars">5</a></li>
</ul>

vot.php

<?php
$vot = $_GET['vot'];
if (is_numeric($vot) && $vot <= 5)
{
	// facem UPDATE in tabela cu voturi

	// ne intoarcem la pagina de vot
	header('Location: ' . $_SERVER['HTTP_REFERER']);
}
else
{
	// ne intoarcem la pagina de vot
	header('Location: ' . $_SERVER['HTTP_REFERER']);
}

Imaginea o puteti descarca de aici.

Folosim doar o imagine PNG de 30x60 pixeli, in prima jumatate va fi o stea simpla iar in a doua jumatate a pozei va fi o steluta colorata. Sper ca stiti de cate ori are voie un IP sa voteze intr-o singura zi sau cum sa faceti update la o tabela cu voturi.

Intrebari?

3 thoughts on “Vot cu ajutorul PHP si CSS”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.