Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Sistema de monetização similar ao Adsense e Boo-Box
O Usuário tem sua conta com seu saldo em dinheiro;
para ganhar dinheiro ele deve receber cliks seus anúncios (links) ,
ex: A Pessoa clica ne um link imprimido na página,
caso essa pessoa tenha 15 pontos e o link valesse 10 pontos ele iria pra 25 e assim por diante.
No caso deveria ter uma página para computar o clique e depois redirecionar para o destino ;D
Segue abaixo as estruturas das duas tabelas que eu criei: user ( para gravar os usuarios e seus pontos ( dinheiro ) e links ( as publicidades, banners e outro com seu valor marcado como ponto )
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`login` varchar(150) NOT NULL,
`senha` varchar(150) NOT NULL,
`pontos` int(15) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `links` (
id int(11) NOT NULL AUTO_INCREMENT,
url varchar(250) NOT NULL,
pontos int(25) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Já criei as seguintes páginas:
login.php - Área de login e quando inicia a sessão MM_Username;
Caso queira o Código vou colocar em Spoiler:
<?php require_once('Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['login'])) {
$loginUsername=$_POST['login'];
$password=$_POST['senha'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "painel.php";
$MM_redirectLoginFailed = "erro.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_conexao, $conexao);
$LoginRS__query=sprintf("SELECT login, senha FROM users WHERE login=%s AND senha=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $conexao) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Logar</title>
<style type="text/css">
#apDiv1 {
position:absolute;
left:10px;
top:30px;
width:245px;
height:85px;
z-index:1;
}
</style>
</head>
<body>
<div id="apDiv1">
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="200" border="0">
<tr>
<td>Login</td>
<td><label for="login"></label>
<input type="text" name="login" id="login" /></td>
</tr>
<tr>
<td>Senha</td>
<td><label for="senha"></label>
<input type="text" name="senha" id="senha" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="logar" id="logar" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
**painel.php** - No momento responsável por mostrar o saldo do usuário e também mostrar as campanhas;
Segue em Spoiler o código caso queira:
<?php require_once('Connections/conexao.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// Logout the current user.
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_MM_Username = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_MM_Username = $_SESSION['MM_Username'];
}
mysql_select_db($database_conexao, $conexao);
$query_MM_Username = sprintf("SELECT * FROM users WHERE login = %s", GetSQLValueString($colname_MM_Username, "text"));
$MM_Username = mysql_query($query_MM_Username, $conexao) or die(mysql_error());
$row_MM_Username = mysql_fetch_assoc($MM_Username);
$totalRows_MM_Username = mysql_num_rows($MM_Username);
mysql_select_db($database_conexao, $conexao);
$query_Recordset1 = "SELECT * FROM links";
$Recordset1 = mysql_query($query_Recordset1, $conexao) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Painel</title>
<style type="text/css">
#apDiv1 {
position:absolute;
left:12px;
top:114px;
width:297px;
height:184px;
z-index:1;
}
</style>
</head>
<body>
<table width="694" border="0">
<tr>
<td width="85">Logado com:</td>
<td width="147"><?php echo $row_MM_Username['login']; ?></td>
<td width="171">Disponivel para pagamento:</td>
<td width="203">R$<?php echo $row_MM_Username['pontos']; ?>,00</td>
<td width="66"> <a href="<?php echo $logoutAction ?>">Sair [X]</a></td>
</tr>
</table>
<hr />
<p>Liks</p>
<p> </p>
<table border="0" cellpadding="5" cellspacing="5">
<tr>
<td width="100">id</td>
<td width="112">url</td>
<td width="194">pontos</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['id']; ?></td>
<td><?php echo $row_Recordset1['url']; ?></td>
<td>R$<?php echo $row_Recordset1['pontos']; ?>,00</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($MM_Username);
mysql_free_result($Recordset1);
?>
link.php - Responsável por pegar o id da campanha e redirecionar o link
Obs: Essa página esta incompleta, aqui que eu parei, não sei oque fazer pra quando a pessoa entrar aqui automaticamente computar + o valor do link ex: A Pessoa entra na página: link.php?url=1 essa campanha de id 1 vale 50 centavos automaticamente é adicionado 50 pontos para o usuário;
Segue em Spoiler o Código.
<?php require_once('Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_Recordset1 = "-1";
if (isset($_GET['url'])) {
$colname_Recordset1 = $_GET['url'];
}
mysql_select_db($database_conexao, $conexao);
$query_Recordset1 = sprintf("SELECT * FROM links WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $conexao) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Link</title>
</head>
<meta http-equiv="refresh" content="1; url=<?php echo $row_Recordset1['url']; ?>">
<body>
<?php echo $row_Recordset1['url']; ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Ninguém?
>
Ninguem o que, exatamente ?
Não vi qual a duvida de forma explicita, apenas uma descrição de algo e vários códigos.
Leia direito o inicio que você vai saber minha duvida!
Ninguem o que, exatamente ?
Não vi qual a duvida de forma explicita, apenas uma descrição de algo e vários códigos.