1
I’m developing an advertising system via link and when a user clicked on the link would open a new window and count as a visit and cash the balance of the advertiser, but it’s not working and I don’t know what’s going wrong:
<?php
ini_set('display_errors', 0);
require_once '../global.php';
require_once ROOT_PATH . '/inc/analyzer.class.php';
function kill() { System::redirect(SITE_LOCATION); exit; };
if (isset($_GET['uid']) && isset($_GET['url'])) {
$G_UID = intval($_GET['uid']);
$G_URL_R = $G_UID . '/' . ($_GET['adt'] != 1 ? 'banner/' : '');
$G_URL = $_SERVER['REQUEST_URI'];
$G_URL = substr($G_URL, strpos($G_URL, $G_URL_R) + strlen($G_URL_R));
$G_ADT = $_GET['adt'] != 1 ? 'Top Banner' : 'Interstitial';
$urlsb = substr($G_URL, 0, strpos($G_URL, '://'));
if (!$urlsb) {
$G_URL = 'http://' . $G_URL;
}
if (!is_numeric($G_UID) || !Utilities::validateURL($G_URL)) {
kill();
}
} else if(!preg_match('|^[0-9a-zA-Z]{1,6}$|', $_GET['to'])) {
kill();
}
$G_SHORT = false;
if ($G_UID && $G_URL && $G_ADT) {
$surl = SITE_LOCATION;
$db = System::getDB();
$user = $G_UID;
if ($tmp = $db->getField($_GLOBAL['TABLES']['LINKS'], 'short_url',
"`long_url`='{$G_URL}' AND `adtype`='{$G_ADT}' AND `user`='{$user}'")) {
$short = $tmp;
$data = System::getDB()->getRows($_GLOBAL['TABLES']['LINKS'], "`short_url`='{$short}'", '', '1');
} else {
$data = array('long_url' => $G_URL, 'adtype' => $G_ADT, 'user' => $user);
$db->query('LOCK TABLES ' . $_GLOBAL['TABLES']['LINKS'] . ' WRITE;');
$lid = $db->insert($_GLOBAL['TABLES']['LINKS'], $data);
$db->query('UNLOCK TABLES');
$short = $surl . Utilities::compressInt($lid);
$db->update($_GLOBAL['TABLES']['LINKS'], array('short_url' => $short), "`id`='{$lid}'");
$data = System::getDB()->getRows($_GLOBAL['TABLES']['LINKS'], "`id`='{$lid}'", '', '1');
}
$G_SHORT = $short;
} else {
$surl = Utilities::removeURLQueries(Utilities::getCurrentURL());
$data = System::getDB()->getRows($_GLOBAL['TABLES']['LINKS'], "`short_url`='{$surl}'", '', '1');
}
$lid = $data['id'];
$oid = $data['user'];
$url = $data['long_url'];
$title = $data['title'];
$adtyp = $data['adtype'] == 'Interstitial' ? 1 : 2;
if (!$url) kill();
if ($data['adtype'] == 'None') {
$analyzer = new Analyzer($lid, $oid, 0);
$analyzer->_record($adtype);
System::redirect($url);
}
function get_ad() {
global $_GLOBAL, $data;
$a = new Analyzer(0, 0, 0);
if ($a->_isCrawler()) die('Crawlers are not allowed here');
$db = System::getDB();
$t = $data['adtype'] != 'Interstitial' ? 'Banner' : 'Interstitial';
$cc = $a->country($a->ip());
$ci = $db->getField($_GLOBAL['TABLES']['PACKAGES'], 'id', "`code`='{$cc}' AND `advert_type`='{$t}'");
$c = $db->getRows($_GLOBAL['TABLES']['CAMPAIGNS'], "`status`='2' AND `advert_type`='{$t}'");
$valid = array();
for ($i = 0; $i < count($c); $i++) {
if ($c[$i]['spent_today'] >= $c[$i]['daily_budget'] && $c[$i]['daily_budget'] != 0) continue;
$pkg = explode(';', $c[$i]['packages']);
foreach ($pkg as $p) {
$t = explode(',', $p);
if ($t[0] == $ci || $t[0] == '1' || $t[0] == '242') $valid[] = $c[$i];
}
}
return $valid[rand(0, count($valid) - 1)];
}
$AD = get_ad();
$aid = $AD['id'] | 0;
if ($adtyp == 2) {
$analyzer = new Analyzer($lid, $oid, $aid);
$analyzer->_record('top_banner', 3);
}
$_user = new User($_GLOBAL['TABLES']['USERS'], $oid, System::getDB());
?>
Does not work total_clicks, views_left, spent_today, and status.
Gave the following errors:
Warning: file_get_contents(/var/www/inc/VERSION.NS): failed to open stream: No such file or directory in /var/www/inc/const.inc.php on line 22
Notice: Undefined index: UID in /var/www/global.php on line 30
Notice: Undefined variable: G_UID in /var/www/fly/index.php on line 27
Notice: Undefined index: HTTPS in /var/www/inc/Utilities.class.php on line 41
Welcome to Stack Overflow! It might be interesting to read the following links: [tour], [help], [Ask]
– gmsantos
Comment the first line of your code
ini_set('display_errors', 0);
. Without it it will be possible to see which errors your page is returning.– gmsantos
Watch these warnings and where they are situated.
– Jorge B.
Not getting it for you.
– feliphe felix
The program is not finding the way
/var/www/inc/VERSION.NS
check if the file is actually in that folder.– Antony Alkmim