For Hen Script (mysql_query API) @ Quick Coding:
100 Coins als Belohnung dafür dass man den Link verbreitet und wenn jemand drauf klickt
1x Pro IP
Weitere Prüfungen sind nurnoch Formsache...
Dauer des Codings hierfür: 10min
PHP Code:
<?
class reflink {
private $db;
private $bonus;
public function __construct($database)
{
$this->db = $database;
// Coins für Reflink klick
$this->bonus = 100;
}
public function getLink($value)
{
$qry = 'SELECT id FROM account.account WHERE login LIKE "'.$_SESSION['user_name'].'";';
$exec = mysql_query($qry, $this->db)or die(mysql_error());
$id = mysql_fetch_object($exec)->id;
if(empty($id))
throw new Exception('No id found');
return $id;
}
public function doAction($value)
{
if(!$this->checkInt($value))
return 'Invalid reflink!';
if(!$this->checkRef($value))
return 'You already voted';
$qry = 'INSERT INTO account.refcheck VALUES ("'.$value.'","'.$this->getIP().'",NOW());';
$exec = mysql_query($qry, $this->db);
$qry = 'UPDATE account.account SET coins=coins+'.$this->bonus.' WHERE id="'.$value.'";';
$exec = mysql_query($qry, $this->db);
return 'Reflinking successful!';
}
private function checkRef($value)
{
$qry = 'SELECT count(ip) AS sum FROM account.refcheck WHERE id="'.$value.'" AND ip="'.$this->getIP().'" and AND `date` >= CAST(NOW() - INTERVAL 1 DAY AS DATE);';
$exec = mysql_query($qry, $this->db);
$count = mysql_fetch_object($exec)->sum;
if($count > 0)
return false;
return true;
}
private function getIP()
{
$ip = trim(addslashes($_SERVER['REMOTE_ADDR']));
return $ip;
}
private function checkInt($value) {
$checkit = preg_match("/^[0-9]+$/",$value);
if($checkit) return true;
else return false;
}
}
$this->reflink = new reflink($sqlServ);
if(!empty($_SESSION['user_name']))
{
echo 'Your reflink:
<input type="text" value="http://your-page.com/?p=reflink&id='.$this->reflink->getLink($_SESSION['user_name']).'" />
';
}
if(!empty($_GET['p']) && $_GET['p']=='reflink' && !empty($_GET['id']))
{
echo $this->reflink->doAction($_GET['id']);
}
?>
PS: Dieses Script ist nicht getestet (Fee-Coding)
HF damit
#Edit:
Hatte nochn bissel LW und ne lustige Idee:
Leveln durch Reflink, damit meine ich:
Pro erfolgreichen Reffer bekommt man exp und steigt auf der HP im Level auf, wobei man pro lv. Coins oder anderes Zeug bekommt (Items, was weiß ich!?)
Hier mal ein kleiner Entwurf:
exp Class
PHP Code:
class exp {
private $db;
public function __construct()
{
$this->db = new $database;
}
public function setExp($userID, $exp)
{
if($exp > 0)
$exp = '+'.$exp;
$sql = 'UPDATE '.$this->db->webdb['level'].'.exp SET exp=exp'.$exp.' WHERE uid='.$userID.';';
$result = $this->db->exec($this->db->web, $sql);
if(empty($result) || $result === false)
return false;
else
return true;
}
public function getExp($userID)
{
$sql = 'SELECT exp FROM '.$this->db->webdb['level'].'.exp WHERE uid='.$userID.';';
$result = mysqli_fetch_object($this->db->exec($this->db->web, $sql))->exp;
if(empty($result) || $result === false)
return false;
else
return true;
}
}
Level Class
PHP Code:
<?php
class level {
private $exp;
private $expTmp;
private $expNeed;
private $level;
public function __construct()
{
}
public function getLevel($userID)
{
$this->exp = new exp;
$this->expTmp = $this->exp->getExp($userID);
$this->expNeed = 100;
$this->level = 0;
while($this->expTmp >= $this->expNeed)
{
$this->expNeed = $this->expNeed + ($this->expNeed / 50);
$this->expTmp = $this->expTmp - $this->expNeed;
$this->level++;
}
return $this->level;
}
}
?>
example php
PHP Code:
function __autoload($name) {
include("./".$name.".class.php");
}
spl_autoload_register("__autoload");
$level = new level;
echo $level->getLevel(1);