#!/usr/bin/perl
# set parameters
$mode = 'test'; # change mode from "test" to "live" when you are done testing
# end parameters
use URI::URL;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use HTTP::Request::Common;
# user agent and IP: used for ad targeting
$ENV{'HTTP_USER_AGENT'} = $ENV{'HTTP_X_DEVICE_USER_AGENT'} if ($ENV{'HTTP_X_DEVICE_USER_AGENT'});
$ua = URI::URL->new($ENV{'HTTP_USER_AGENT'});
$ip = URI::URL->new($ENV{'REMOTE_ADDR'});
$la = lc(substr($ENV{'HTTP_ACCEPT_LANGUAGE'},0,2));
$la =~ s/[^a-z]//g;
$url = 'http://www.adshandy.com/cgi-bin/pm/getad.cgi?s=wIg0ao0Ug3Zk7&i=' . $ip . '&b=' . $ua . '&l=' . $la . '&m=' . $mode;
# fetch ad
my $ua = LWP::UserAgent->new();
$ua->timeout(3);
my $response = $ua->request(GET "$url");
if (!$response->is_error()) {
# display ad
my $content = $response->content();
chomp $content;
$content =~ s/\n//gi;
print $content;
}