Jump to content

Big Problem


hash1

Recommended Posts

When members view ads at my site after the counter counts down and you click the right verification but after you do that it doesnt do anything is suppose to credit the member that viewed the site.

 

<?php
session_start();
header('Content-type: text/javascript');

require('config.php');
require('funciones.php');

// SOME USEFUL FUNCTIONS
// ---------------------
function destroy() {
    $_SESSION['captcha']=null;
    exit();
}

function error_message($msg) {
    global $fail_code;
    echo <<<EOT
        document.getElementById('timer').setAttribute('class','hidden');
        document.getElementById('alert').setAttribute('class','');
        document.getElementById('alert').innerHTML="$msg"+'<p><a href="javascript&#058;closealert()">Close</a></p>';
EOT;
    destroy();
}

// CHECKING
// --------

// checking if user is logged in
if(!isset($_COOKIE["usNick"]) || !isset($_COOKIE["usPass"])) {
    error_message('Not logged in or session cookie expired.\nPlease log-in again.');
}

// checking captcha
if(!isset($_GET['code']) || $_GET['code']!=$_SESSION['captcha']) {

$user = uc($_COOKIE["usNick"]);
$ip=getRealIP();
$date = date("F j, Y");
$time = date("g:i a");
    mysql_query("INSERT INTO cheaters(user,ip, date, time) VALUES ('$user','$ip', '$date','$time')") or die(mysql_error());
    error_message('Wrong security code!<br><br>This is a bot detection and your account will be deleted if this persists. Please contact support for further information.');
}

// checking username and password
$user = uc($_COOKIE["usNick"]);
$pass = uc($_COOKIE["usPass"]);
$user_query = mysql_query("SELECT * FROM users WHERE username='$user' AND password='$pass'") or die(mysql_error());        

if(mysql_num_rows($user_query)==0) {
    error_message('Bad username/password.\nPlease log-in again.');
}

// checking if the ad is still alive
$ad_id = limpiar($_GET["ad"]);  
$ad_query = mysql_query("SELECT id FROM ads WHERE id='$ad_id' AND tipo='ads' AND CONVERT(members,UNSIGNED) < CONVERT(plan,UNSIGNED)") or die(mysql_error());

if (mysql_num_rows($ad_query)==0) {
    error_message('Too late! Ad expired!');
}

// UPDATE AD AND VISIT INFO
// ------------------------
$visit_query = mysql_query("SELECT * FROM ads WHERE user = '$user' AND ident= '$ad_id' AND tipo='visit'") or die(mysql_error());
$actual_time= date(time());


// checking and registering visits
$ip=getRealIP();
if(mysql_num_rows($visit_query)>0) {
    $visit_row = mysql_fetch_array($visit_query);
    $lastvisit_time=$visit_row['visitime'];

    if($actual_time < date($lastvisit_time + (24 * 60 * 60))) {
        error_message('You have to wait 24h before visiting the same sponsor again.');
    }
    
    mysql_query("UPDATE ads SET visitime='$actual_time', ip='$ip' WHERE user='$user' AND ident='$ad_id' AND tipo='visit'") or die(mysql_error());
} else {
    mysql_query("INSERT INTO ads(user,ip,ident,tipo,visitime) VALUES ('$user','$ip','$ad_id','visit','$actual_time')") or die(mysql_error());
}

// updating ad status
mysql_query("UPDATE ads SET members = CONVERT(members,UNSIGNED) + 1 WHERE id='$ad_id'") or die(mysql_error());


// UPDATE USER INFO
// ----------------
$user_row = mysql_fetch_array($user_query);

// loading click configuration
foreach(array('click','referalclick','premiumclick','premiumreferalc') as $item) {
    $query = mysql_query("SELECT price FROM config WHERE item='$item' AND howmany='1'") or die(mysql_error());
    $row = mysql_fetch_row($query);
    ${$item} = $row[0];
}

// updating money and visits for the user
mysql_query("UPDATE users SET money = money + IF(account='premium',$premiumclick,$click), visits = CONVERT(visits,UNSIGNED) + 1 WHERE username='$user'") or die(mysql_error());

// updating money and visits for the referer, if any
$referer=$user_row['referer'];
if ($referer!=''){
        mysql_query("UPDATE users SET money = money + IF(account='premium',$premiumreferalc,$referalclick), referalvisits = CONVERT(referalvisits,UNSIGNED) + 1 WHERE username='$referer'") or die(mysql_error());
}

// HOORAY! SUCCESS!
echo <<<EOT
document.getElementById('timer').setAttribute('class','success');
document.getElementById('timer').innerHTML='Success!';
EOT;
destroy();
?>

Heres the code for it any help?

Link to comment
https://forums.phpfreaks.com/topic/109193-big-problem/
Share on other sites

actually this might be the right one

 

<?php
session_start();

define('AD_TIMER',30); // number of seconds for the timer
define('AD_TIMEOUT',30); // if the page doesn't load in AD_TIMEOUT seconds, the timer starts anyway. Set to 0 to disable this feature

require('config.php');
require('funciones.php');

$logged_in=isset($_COOKIE["usNick"]) && isset($_COOKIE["usPass"]);
$ad_id=limpiar($_GET["ad"]);
$ad_result=mysql_query("SELECT * FROM ads WHERE id='$ad_id'");

// Checking ad existence
if (mysql_num_rows($ad_result)==0) {
echo "Ad doesn't exist";
exit();
}
$ad_row=mysql_fetch_array($ad_result);

// Increasing counter
if(!$logged_in) {
mysql_query("UPDATE ads SET outside=outside+1 WHERE id='$ad_id'");
}

// Captcha functions
// Generates $num random codes of $len length
function get_codes($num,$len) {
for($i=0;$i<$num;++$i) {
$codes[]=substr(strtoupper(md5(rand(1000,1000000000))),0,$len);
}
return $codes;
}

$codes=get_codes(4,3);
$_SESSION['captcha']=$codes[rand(0,count($codes)-1)];

?>
<html>
<head>
<title><? include('sitename.php'); ?> | .view .click .make money</title>
<link rel="stylesheet" type="text/css" href="css/adview.css">
<style type="text/css">
<?php if($logged_in): ?>
.hidden { display: none; }
#timer { width: 64px; height: 64px; position:fixed; top:5px; left:5px; background: #000 no-repeat 50% 50%; z-index:100000; padding:5px;
background-image:url('images/loading.gif');
background-image:url('images/success.png');
background-image:url('images/fail.png');
background-image:none;}
#timer.loading { background-image: url('images/loading.gif'); text-indent: -99999px; }
#timer.countdown { font: 48px bold Helvetica, Verdana, sans-serif; color: #fff; text-align:center; }
#timer.success { background-image: url('images/success.png'); text-indent: -99999px; }

#code, #alert { background: #000; position: absolute; top:33%; left:33%; width:33%; height:33%; z-index:10000; color: #c0c0c0; font-weight:bold; text-align:center; padding:20px; }
#code img { display:block; border: 2px solid #c0c0c0; margin:10px auto; }
#alert a, #code a, #alert a:visited, #code a:visited { color: #fff; text-decoration: none; padding: 5px; }
#alert a:hover, #code a:hover { color: #000; background: #fff }

#alert { background: url('images/fail.png') no-repeat 50% 20px #000; height:100px; padding-top:78px; color:#fff; }
<?php else: ?>
#message { position: absolute; top:0; left:0; width:100%; height: 30px; color:#fff; background: #000; text-align:center; z-index: 10000; }
<?php endif; ?>
iframe { position: absolute; left:0;top:0;width:100%;height:100%; z-index: 100; }
</style>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<?php if($logged_in): ?>
<script type="text/javascript">
var ad='<?php echo $ad_id ?>';

if(window.top!=window) { window.top.location=window.location; }

function countdown(time) {
if(time==0) {
document.getElementById('timer').setAttribute('class','hidden');
document.getElementById('code').setAttribute('class','');
} else {
var timer=document.getElementById('timer');
timer.setAttribute('class','countdown');
timer.innerHTML=time;
setTimeout('countdown('+(time-1)+')',1000);
}
}

function captcha(code) {
document.getElementById('code').setAttribute('class','hidden');
document.getElementById('timer').setAttribute('class','loading');
var script=document.createElement('script');
script.setAttribute('type','text/javascript');
script.setAttribute('src','visit.php?ad=<?php echo $ad_id; ?>&code='+code);
document.getElementsByTagName('head')[0].appendChild(script);
return false;
}

function closealert() {
document.getElementById('alert').setAttribute('class','hidden');
}

window.onload=function() {
if(window.startedCountdown) { return; }
else {
countdown(<?php echo AD_TIMER ?>);
window.startedCountdown=true;
}
}
<?php if(AD_TIMEOUT): ?>
setTimeout('window.onload()',<?php echo AD_TIMEOUT; ?>000);
<?php endif; ?>
</script>
<?php endif; ?>
</head>

<body>
<?php if($logged_in): ?>
<div id="timer" class="loading">loading...</div>
<div id="code" class="hidden">
<p>Please choose the code displayed in the picture</p>
<img src="captcha.php" width="130" height="60" />
<?php foreach($codes as $c): ?>
<a href="#" onclick="return captcha('<?php echo $c;?>');"><?php echo $c; ?></a> 
<?php endforeach; ?>
</div>
<div id="alert" class="hidden"></div>
<?php else: ?>
<div id="message">
To take credit for this visit, please log-in.
</div>
<?php endif; ?>
<iframe src="<?php echo $ad_row['url']; ?>" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="100%" scrolling="yes" width="100%" id="site"></iframe>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/109193-big-problem/#findComment-560140
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.