From Very Old Code: Geo/Country Based Addvertisement Display

<?php
require_once "geo/geoip/geoip.inc";
function main()
{
global $country, $ip, $currentTime;
$currentTime = time(); //mktime();
$gi = geoip_open("geo/geoip/GeoIP.dat", GEOIP_STANDARD);
$ip = $_SERVER["REMOTE_ADDR"];
$country = geoip_country_code_by_addr($gi, $ip);
//echo $country;
geoip_close($gi);
setcookie("geo", $country, time() + 15552000, "/", $base . $domain, 0); //6 month cookie
$link = connect();
displayClientWebSite($ip, $country, $currentTime, $link);
}

//logic to decide whether to display a site or not
//also display a site

function displayClientWebSite($ip, $country, $currentTime, $link)
{
//check if the ip is in our database
$sqlCheckIp = " select * from ip_and_display_track where ip='$ip' order by accessed desc limit 1";
$result = mysqli_query($link, $sqlCheckIp);
if (!$result) {
} else {
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$accessed = $row['accessed'];
if (abs($currentTime - $accessed) >= 0) {
require 'geo/campaign.php';
exit;
} else {
//die('i am dead');
//exit;
}
} else {
require 'geo/campaign.php';
exit;
}
}
}

/* connect to database */
function connect()
{
// we connect to example.com and port 3307
$link = mysqli_connect('localhost', "db", "pass");
if (mysqli_connect_errno()) {
die('Could not connect: ' . mysqli_connect_error());
}

if (!mysqli_select_db($link, "client_traffic")) {
echo "Unable to select mydbname: " . mysqli_error($link);
exit;
}

return $link;
}

$country = "";
$ip = "";
$gi = "";
$currentTime = "";
time();
main();
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
?>
<script src="//rtb.adx1.com/pixels/pixel.js?id=166606&event=conversion&value=55"></script>

Permanent link to this article: http://bangla.sitestree.com/from-very-old-code-geo-country-based-addvertisement-display/

Leave a Reply