anyone have php script admob to showing ads with php? Example like this.. admob.php?id=[YOUR PUBLISHER ID] and to show it using javascript <script src="http://yourhost/admob.php?id=a14xxxx"></script>
php ads with external javascript
Collapse
X
-
PHP Code:<?php
if(isset($_GET['publisher_id'])) $publisher_id=$_GET['publisher_id'];
else $publisher_id='your defalt publisher id';
$admob_params = array(
'PUBLISHER_ID' => $publisher_id, // Required to request ads. To find your Publisher ID, log in to your AdMob account and click on the "Sites & Apps" tab.
'ANALYTICS_ID' => 'your_analytics_site_id', // Required to collect Analytics data. To find your Analytics ID, log in to your Analytics account and click on the "Edit" link next to the name of your site.
'AD_REQUEST' => true, // To request an ad, set to TRUE.
'ANALYTICS_REQUEST' => false, // To enable the collection of analytics data, set to TRUE.
'TEST_MODE' => false, // While testing, set to TRUE. When you are ready to make live requests, set to FALSE.
// Additional optional parameters are available at: [url=http://developer.admob.com/wiki/AdCodeDocumentation]Requests - Admob For Developers[/url]
'OPTIONAL' => array()
);
$ad_mode = false;
if (!empty($admob_params['AD_REQUEST']) && !empty($admob_params['PUBLISHER_ID'])) $ad_mode = true;
$analytics_mode = false;
if (!empty($admob_params['ANALYTICS_REQUEST']) && !empty($admob_params['ANALYTICS_ID']) && !$pixel_sent) $analytics_mode = true;
$protocol = 'http';
if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') $protocol = 'https';
$rt = $ad_mode ? ($analytics_mode ? 2 : 0) : ($analytics_mode ? 1 : -1);
if ($rt == -1) return '';
list($usec, $sec) = explode(' ', microtime());
$params = array('rt=' . $rt,
'z=' . ($sec + $usec),
'u=' . urlencode($_SERVER['HTTP_USER_AGENT']),
'i=' . urlencode($_SERVER['REMOTE_ADDR']),
'p=' . urlencode("$protocol://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
'v=' . urlencode('20081105-PHPCURL-acda0040bcdea222'));
$sid = empty($admob_params['SID']) ? session_id() : $admob_params['SID'];
if (!empty($sid)) $params[] = 't=' . md5($sid);
if ($ad_mode) $params[] = 's=' . $admob_params['PUBLISHER_ID'];
if ($analytics_mode) $params[] = 'a=' . $admob_params['ANALYTICS_ID'];
if (!empty($_COOKIE['admobuu'])) $params[] = 'o=' . $_COOKIE['admobuu'];
if (!empty($admob_params['TEST_MODE'])) $params[] = 'm=test';
if (!empty($admob_params['OPTIONAL'])) {
foreach ($admob_params['OPTIONAL'] as $k => $v) {
$params[] = urlencode($k) . '=' . urlencode($v);
}
}
$ignore = array('HTTP_PRAGMA' => true, 'HTTP_CACHE_CONTROL' => true, 'HTTP_CONNECTION' => true, 'HTTP_USER_AGENT' => true, 'HTTP_COOKIE' => true);
foreach ($_SERVER as $k => $v) {
if (substr($k, 0, 4) == 'HTTP' && empty($ignore[$k]) && isset($v)) {
$params[] = urlencode('h[' . $k . ']') . '=' . urlencode($v);
}
}
$post = implode('&', $params);
$request = curl_init();
$request_timeout = 1; // 1 second timeout
curl_setopt($request, CURLOPT_URL, 'http://r.admob.com/ad_source.php');
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_TIMEOUT, $request_timeout);
curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $request_timeout);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Connection: Close'));
curl_setopt($request, CURLOPT_POSTFIELDS, $post);
list($usec_start, $sec_start) = explode(' ', microtime());
$contents = curl_exec($request);
list($usec_end, $sec_end) = explode(' ', microtime());
curl_close($request);
if ($contents === true || $contents === false) $contents = '';
echo $contents;
?>
-
@Gum thank you, i will try
Added after 23 minutes:
not working brother..
Parse error: syntax error, unexpected T_STRING, expecting
')' in /home/waphacke/public_ html/str/whcservice.php on line 4
how to run it with javascript? Example like this <script src="http://sun4r.com/iklan.php?id=a14xxx"></script>Last edited by cavaleri; 30.03.11, 15:24.
Comment
-
admob_javascript.php
PHP Code:<?php
header("Content-type: text/javascript");
if(isset($_GET['publisher_id'])) $publisher_id=$_GET['publisher_id'];
else $publisher_id='a14c39c3ea847e49';
$admob_params = array(
'PUBLISHER_ID' => $publisher_id, // Required to request ads. To find your Publisher ID, log in to your AdMob account and click on the "Sites & Apps" tab.
'ANALYTICS_ID' => 'your_analytics_site_id', // Required to collect Analytics data. To find your Analytics ID, log in to your Analytics account and click on the "Edit" link next to the name of your site.
'AD_REQUEST' => true, // To request an ad, set to TRUE.
'ANALYTICS_REQUEST' => false, // To enable the collection of analytics data, set to TRUE.
'TEST_MODE' => true, // While testing, set to TRUE. When you are ready to make live requests, set to FALSE.
// Additional optional parameters are available at: [url=http://developer.admob.com/wiki/AdCodeDocumentation]Requests - Admob For Developers[/url]
'OPTIONAL' => array()
);
$ad_mode = false;
if (!empty($admob_params['AD_REQUEST']) && !empty($admob_params['PUBLISHER_ID'])) $ad_mode = true;
$analytics_mode = false;
if (!empty($admob_params['ANALYTICS_REQUEST']) && !empty($admob_params['ANALYTICS_ID']) && !$pixel_sent) $analytics_mode = true;
$protocol = 'http';
if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') $protocol = 'https';
$rt = $ad_mode ? ($analytics_mode ? 2 : 0) : ($analytics_mode ? 1 : -1);
if ($rt == -1) return '';
list($usec, $sec) = explode(' ', microtime());
$params = array('rt=' . $rt,
'z=' . ($sec + $usec),
'u=' . urlencode($_SERVER['HTTP_USER_AGENT']),
'i=' . urlencode($_SERVER['REMOTE_ADDR']),
'p=' . urlencode("$protocol://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
'v=' . urlencode('20081105-PHPCURL-acda0040bcdea222'));
$sid = empty($admob_params['SID']) ? session_id() : $admob_params['SID'];
if (!empty($sid)) $params[] = 't=' . md5($sid);
if ($ad_mode) $params[] = 's=' . $admob_params['PUBLISHER_ID'];
if ($analytics_mode) $params[] = 'a=' . $admob_params['ANALYTICS_ID'];
if (!empty($_COOKIE['admobuu'])) $params[] = 'o=' . $_COOKIE['admobuu'];
if (!empty($admob_params['TEST_MODE'])) $params[] = 'm=test';
if (!empty($admob_params['OPTIONAL'])) {
foreach ($admob_params['OPTIONAL'] as $k => $v) {
$params[] = urlencode($k) . '=' . urlencode($v);
}
}
$ignore = array('HTTP_PRAGMA' => true, 'HTTP_CACHE_CONTROL' => true, 'HTTP_CONNECTION' => true, 'HTTP_USER_AGENT' => true, 'HTTP_COOKIE' => true);
foreach ($_SERVER as $k => $v) {
if (substr($k, 0, 4) == 'HTTP' && empty($ignore[$k]) && isset($v)) {
$params[] = urlencode('h[' . $k . ']') . '=' . urlencode($v);
}
}
$post = implode('&', $params);
$request = curl_init();
$request_timeout = 1; // 1 second timeout
curl_setopt($request, CURLOPT_URL, 'http://r.admob.com/ad_source.php');
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_TIMEOUT, $request_timeout);
curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $request_timeout);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Connection: Close'));
curl_setopt($request, CURLOPT_POSTFIELDS, $post);
list($usec_start, $sec_start) = explode(' ', microtime());
$contents = curl_exec($request);
list($usec_end, $sec_end) = explode(' ', microtime());
curl_close($request);
if ($contents === true || $contents === false) $contents = '';
echo 'document.write(\''.$contents.'\');';
?>PHP Code:echo '<script src="http://site.com/admob_javascript.php?publisher_id=a14c39c3ae847e49" type="text/javascript"></script>';
Comment
Comment