Contador de Cliques
Contador de Cliques em php
--
-- Estrutura da tabela `cliques`
--
CREATE TABLE IF NOT EXISTS `cliques` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`banner` varchar(100) NOT NULL,
`url` varchar(100) NOT NULL,
`cliques` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Extraindo dados da tabela `cliques`
--
INSERT INTO `cliques` (`id`, `banner`, `url`, `cliques`) VALUES
(1, 'banner.jpg', 'http://www.adaptinsite.com/blog/', 0);
Pagina de conexão connect_data_base.php
<?php
class conexao {
public $host="localhost";
public $user="root";
public $pass="";
public $database="contador";
public $connect="";
public $select="";
function __construct() {
$this->connect=mysql_connect($this->host,$this->user,$this->pass) or die (mysql_error());
$this->select=mysql_select_db($this->database,$this->connect) or die (mysql_error());
}
}
$conexao=new conexao();
?>
agora nossa pagina index.php
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contador de Cliques</title>
</head>
<body>
<?php
/*by ozorio*/
include ("connect_data_base.php");
class clique {
public $cliques = "";
public $result_sql = "";
public $sql = "";
public $id="";
public $banner="";
function clicar() {
$this->sql = mysql_query("SELECT * FROM cliques");
while($this->result_sql = mysql_fetch_object($this->sql)){
$this->id = $this->result_sql->id;
$this->banner = $this->result_sql->banner;
$this->cliques=$this->result_sql->cliques;
echo'<div align="center"><h2>Contador de Cliques</h2></div>' ;
echo '<div align="center"><a href="funcao.php?id='."$this->id".'" target="_blank"><img src="'." $this->banner".'" border="0" width="250" height="250" title="Click Aqui"/></a></div>';
echo '<br>';
echo'<div align="center"> Total de Cliques:<span style="color:red;"> '.$this->cliques. '</span></div>' ;
}
}
}
$clique=new clique();
$clique->clicar();
?>
</body>
</html>
agora criaremos a pagina com as funçoes do codigo funcao.php
<?php
/*by ozorio*/
include ("connect_data_base.php");
class funcao {
public $cria_cookie = "";
public $cliques = "";
public $sql = "";
public $soma = "";
function __construct() {
$this->id = $_GET['id'];
$this->sql = mysql_query("SELECT * FROM cliques");
while($this->result_sql = mysql_fetch_object($this->sql)){
$this->url = $this->result_sql->url;
$this->cliques = $this->result_sql->cliques;
}
if(!isset($_COOKIE['contador'])){
$this->cria_cookie = "ClicaBanner";
// setamos o cookie para o usuario so clicar uma vez por dia no banner 24 horas
setcookie("contador", $this->cria_cookie, time()+(24*3600));//(1hora x 24)= 24 x 3600segundos = 1hora = 24 horas 1 dia
$this->soma = $this->cliques + 1;
$this->sql = mysql_query("UPDATE cliques SET cliques='$this->soma' WHERE id = '$this->id'");
header("Location: $this->url");
}
if(isset($_COOKIE['contador'])){
header("Location: $this->url");
}
}
}
$funcao=new funcao();
?>
Codigo para download http://www.4shared.com/file/142792732/aa3b15a8/contador_de_cliques.html
Ver Referencia http://www.adaptinsite.com/blog/2009/10/contador-de-cliques-em-php/
--
-- Estrutura da tabela `cliques`
--
CREATE TABLE IF NOT EXISTS `cliques` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`banner` varchar(100) NOT NULL,
`url` varchar(100) NOT NULL,
`cliques` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Extraindo dados da tabela `cliques`
--
INSERT INTO `cliques` (`id`, `banner`, `url`, `cliques`) VALUES
(1, 'banner.jpg', 'http://www.adaptinsite.com/blog/', 0);
Pagina de conexão connect_data_base.php
<?php
class conexao {
public $host="localhost";
public $user="root";
public $pass="";
public $database="contador";
public $connect="";
public $select="";
function __construct() {
$this->connect=mysql_connect($this->host,$this->user,$this->pass) or die (mysql_error());
$this->select=mysql_select_db($this->database,$this->connect) or die (mysql_error());
}
}
$conexao=new conexao();
?>
agora nossa pagina index.php
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contador de Cliques</title>
</head>
<body>
<?php
/*by ozorio*/
include ("connect_data_base.php");
class clique {
public $cliques = "";
public $result_sql = "";
public $sql = "";
public $id="";
public $banner="";
function clicar() {
$this->sql = mysql_query("SELECT * FROM cliques");
while($this->result_sql = mysql_fetch_object($this->sql)){
$this->id = $this->result_sql->id;
$this->banner = $this->result_sql->banner;
$this->cliques=$this->result_sql->cliques;
echo'<div align="center"><h2>Contador de Cliques</h2></div>' ;
echo '<div align="center"><a href="funcao.php?id='."$this->id".'" target="_blank"><img src="'." $this->banner".'" border="0" width="250" height="250" title="Click Aqui"/></a></div>';
echo '<br>';
echo'<div align="center"> Total de Cliques:<span style="color:red;"> '.$this->cliques. '</span></div>' ;
}
}
}
$clique=new clique();
$clique->clicar();
?>
</body>
</html>
agora criaremos a pagina com as funçoes do codigo funcao.php
<?php
/*by ozorio*/
include ("connect_data_base.php");
class funcao {
public $cria_cookie = "";
public $cliques = "";
public $sql = "";
public $soma = "";
function __construct() {
$this->id = $_GET['id'];
$this->sql = mysql_query("SELECT * FROM cliques");
while($this->result_sql = mysql_fetch_object($this->sql)){
$this->url = $this->result_sql->url;
$this->cliques = $this->result_sql->cliques;
}
if(!isset($_COOKIE['contador'])){
$this->cria_cookie = "ClicaBanner";
// setamos o cookie para o usuario so clicar uma vez por dia no banner 24 horas
setcookie("contador", $this->cria_cookie, time()+(24*3600));//(1hora x 24)= 24 x 3600segundos = 1hora = 24 horas 1 dia
$this->soma = $this->cliques + 1;
$this->sql = mysql_query("UPDATE cliques SET cliques='$this->soma' WHERE id = '$this->id'");
header("Location: $this->url");
}
if(isset($_COOKIE['contador'])){
header("Location: $this->url");
}
}
}
$funcao=new funcao();
?>
Codigo para download http://www.4shared.com/file/142792732/aa3b15a8/contador_de_cliques.html
Ver Referencia http://www.adaptinsite.com/blog/2009/10/contador-de-cliques-em-php/
Data | Autor | Changelog | Download |
---|---|---|---|
04/12/2009 2:32am | ozorio silva | - | Versão 1.0 |
Novo Comentário: