Admob Help

Started on the old forum in April 2009 · view the original in the archive · old links redirect here

20 replies · 3,494 views · started 17 years ago · 1 min read

TL;DR · summary of 20 replies
  • gumslone recommended renaming the function to avoid conflicts when using both text and image ads.
  • cobusbo asked for advice on how to place admob.php in a non-indexed directory without copying it.
  • nclemale36 suggested including the admob code directly into main files like index or core, changing account codes accordingly.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

7 participants
brentg Developer · 95 posts #1

I would like to have admob text and image ads on my pages

i use the <?php include(""); ?> function do display my ads

The problem is with admob i can only have code dispalyed(text ads)

<?php include(„admobt“); ?>

but i also want <?php include("admob.php"); ?>(image ads) to display but it gives me this error on page

Fatal error: Cannot redeclare admob_request() (previously declared in /home/mysite/public_html/admobt.php:46) in /home/mysite/public_html/admob.php on line 143

Thanks

Free Mobile Downloads: http://playwap.mobi

GumSlone Administrator Principal · 1,690 posts #2

brentg wrote: Fatal error: Cannot redeclare admob_request() (previously declared in /home/mysite/public_html/admobt.php:46) in /home/mysite/public_html/admob.php on line 143

i think everything is explained clearly in the error message

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

GumSlone Administrator Principal · 1,690 posts #4

brentg wrote: so i cant view text and image ads at the same time?

you can but you need to rename the function

admob_request()

in text or in image ads.

eg to. image_admob_request()

Or you can use the code example below.

<?php
// AdMob Publisher Code
// Language: PHP (fsockopen)
// Version: 20081105
// Copyright AdMob, Inc., All rights reserved
// Documentation at http://developer.admob.com/wiki/Main_Page
//Text ad parameters
$admob_params = array(
  '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: http://developer.admob.com/wiki/AdCodeDocumentation
  'OPTIONAL'          => array()
);

//Image ad parameters 
$admob_params_image = array(
  '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: http://developer.admob.com/wiki/AdCodeDocumentation
  'OPTIONAL'          => array()
);

// Optional parameters for AdMob Analytics (http://analytics.admob.com)
//$admob_params['OPTIONAL']['title'] = "Enter Page Title Here"; // Analytics allows you to track site usage based on custom page titles. Enter custom title in this parameter.
//$admob_params['OPTIONAL']['event'] = "Enter Event Name Here"; // To learn more about events, log in to your Analytics account and visit this page: http://analytics.admob.com/reports/events/add

/* This code supports the ability for your website to set a cookie on behalf of AdMob
 * To set an AdMob cookie, simply call admob_setcookie() on any page that you call admob_request()
 * The call to admob_setcookie() must occur before any output has been written to the page (http://www.php.net/setcookie)
 * If your mobile site uses multiple subdomains (e.g. "a.example.com" and "b.example.com"), then pass the root domain of your mobile site (e.g. "example.com") as a parameter to admob_setcookie().
 * This will allow the AdMob cookie to be visible across subdomains
 */
//admob_setcookie();

/* AdMob strongly recommends using cookies as it allows us to better uniquely identify users on your website.
 * This benefits your mobile site by providing:
 *    - Improved ad targeting = higher click through rates = more revenue!
 *    - More accurate analytics data (http://analytics.admob.com)
 */
 
// Send request to AdMob. To make additional ad requests per page, copy and paste this function call elsewhere on your page.

/////////////////////////////////
// Do not edit below this line //
/////////////////////////////////

// This section defines AdMob functions and should be used AS IS.
// We recommend placing the following code in a separate file that is included where needed.

function admob_request($admob_params) {
  static $pixel_sent = false;

  $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(getip()), 
                  'p=' . urlencode("$protocol://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
                  'v=' . urlencode('20081105-PHPFSOCK-33fdd8e59a40dd9a')); 

  $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_timeout = 1; // 1 second timeout
  $contents = '';
  $errno = 0;
  $errstr = '';
  list($usec_start, $sec_start) = explode(' ', microtime());
  $request = @fsockopen('r.admob.com', 80, $errno, $errstr, $request_timeout);
  if($request) {
    stream_set_timeout($request, $request_timeout);
    $post_body = "POST /ad_source.php HTTP/1.0\r\nHost: r.admob.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($post) . "\r\n\r\n" . $post;
    $post_body_len = strlen($post_body);
    $bytes_written = 0;
    $body = false;

    $info = stream_get_meta_data($request);
    $timeout = $info['timed_out'];
    while($bytes_written < $post_body_len && !$timeout) { 
      $current_bytes_written = fwrite($request, $post_body); 
      if($current_bytes_written === false) return ''; // write failed 
      $bytes_written += $current_bytes_written; 
      if($bytes_written === $post_body_len) break;
      $post_body = substr($post_body, $bytes_written); 
      $info = stream_get_meta_data($request);
      $timeout = $info['timed_out'];
    }

    while(!feof($request) && !$timeout) {
      $line = fgets($request);
      if(!$body && $line == "\r\n") $body = true;
      if($body && !empty($line)) $contents .= $line;
      $info = stream_get_meta_data($request);
      $timeout = $info['timed_out'];
    }
    fclose($request);
    list($usec_end, $sec_end) = explode(' ', microtime());
  }
  else {
    $contents = '';
  }

  if (!$pixel_sent) {
    $pixel_sent = true;
    /*$contents .= "<img src=\"$protocol://p.admob.com/e0?"
              . 'rt=' . $rt
              . '&z=' . ($sec + $usec)
              . '&a=' . ($analytics_mode ? $admob_params['ANALYTICS_ID'] : '')
              . '&s=' . ($ad_mode ? $admob_params['PUBLISHER_ID'] : '')
              . '&o=' . (empty($_COOKIE['admobuu']) ? '' : $_COOKIE['admobuu'])
              . '&lt=' . ($sec_end + $usec_end - $sec_start - $usec_start)
              . '&to=' . $request_timeout
              . '" alt="" width="1" height="1"/>';*/
  }
  
  if(strlen($contents)>5)return $contents. ' [ad]<br/>'; else return '';
}

function admob_setcookie($domain = '', $path = '/') {
  if (empty($_COOKIE['admobuu'])) {    
    $value = md5(uniqid(rand(), true));
    if (!empty($domain) && $domain[0] != '.') $domain = ".$domain";
    if (setcookie('admobuu', $value, mktime(0, 0, 0, 1, 1, 2038), $path, $domain)) {
      $_COOKIE['admobuu'] = $value; // make it visible to admob_request()
    } 
  }
}

function getip() {
    if (validip($_SERVER["HTTP_CLIENT_IP"])) {
        return $_SERVER["HTTP_CLIENT_IP"];
    }
    foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {
        if (validip(trim($ip))) {
            return $ip;
        }
    }
    if (validip($_SERVER["HTTP_X_FORWARDED"])) {
        return $_SERVER["HTTP_X_FORWARDED"];
    } elseif (validip($_SERVER["HTTP_FORWARDED_FOR"])) {
        return $_SERVER["HTTP_FORWARDED_FOR"];
    } elseif (validip($_SERVER["HTTP_FORWARDED"])) {
        return $_SERVER["HTTP_FORWARDED"];
    } elseif (validip($_SERVER["HTTP_X_FORWARDED"])) {
        return $_SERVER["HTTP_X_FORWARDED"];
    } else {
        return $_SERVER["REMOTE_ADDR"];
    }
 }

function validip($ip) {
    if (!empty($ip) && ip2long($ip)!=-1) {
        $reserved_ips = array (
        array('0.0.0.0','2.255.255.255'),
        array('10.0.0.0','10.255.255.255'),
        array('127.0.0.0','127.255.255.255'),
        array('169.254.0.0','169.254.255.255'),
        array('172.16.0.0','172.31.255.255'),
        array('192.0.2.0','192.0.2.255'),
        array('192.168.0.0','192.168.255.255'),
        array('255.255.255.0','255.255.255.255')
        );
 
        foreach ($reserved_ips as $r) {
            $min = ip2long($r[0]);
            $max = ip2long($r[1]);
            if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
        }
        return true;
    } else {
        return false;
    }
 }

USAGE:

echo admob_request($admob_params); //text ad
echo admob_request($admob_params_image); //image ad

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

brentg Developer · 95 posts #7

same error as above and sometimes it just displays the whole admob code on my site??

Free Mobile Downloads: http://playwap.mobi

cobusbo Developer · 117 posts #10

Hi I got a problem asswell I use the following

<?php include("admob.php") ?>

on all the pages where I want the ads wich link to it but the thing is I want to place it in a auto index script to do so I need to place the admob.php file in the same directory as the autoindex then it shows in it.

Check here

I dont want the admob.php to show there Is there maybe a way to edit the first Quote to get the admob.php file from the main folder of the site wich is not getting indexed etc? or add an exclude funtion in the auto index script?

Please help?

GumSlone Administrator Principal · 1,690 posts #11

dont use admob, the have recently suspended my acount too. with reasons wich are not true:

Your account has been disabled for invalid activity or repeated policy violations. Some examples include recurring manual clicks or impressions, violation of our content policies which can be found here, robots, automated click and impression generating tools, third-party services that generate clicks or impressions such as pay-to-click, pay-to-surf, autosurf, and click-exchange programs, or any deceptive software. Please visit our Account Review form if you feel additional information would be valuable in explaining your situation.

i had 1,500 000 ad impressions a day. and about 0,08 % click rate

Soon I will write a full story about it.

the admobsucks.com site in on the way to be online.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

cobusbo Developer · 117 posts #12

well a bud of mine used it and he got his money and used it for advertising so what ads site do you recommend? I only need that admob.php from one place and dont have to copy it to every directory

riderz Lead · 975 posts #13

cobusbo if ur friend use it why not just ask him to help u with that then u can register at google adds and many more i guess u did hear bout Google


Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

cobusbo Developer · 117 posts #14

yes but he don't use it the way i need to use it on auto index scripts and google adds don't pay out via paypal I heard and its more stricked

GumSlone Administrator Principal · 1,690 posts #15

cobusbo wrote: well a bud of mine used it and he got his money and used it for advertising so what ads site do you recommend? I only need that admob.php from one place and dont have to copy it to every directory

i have used it for more than 2 years and i was one of the very first big publishers there, just got some problems with my bank thats why i asked them to hold the payouts, and havent been payed for a half year, so i hade lots of USD in my account, and recently the suspended it.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

nclemale36 Lead · 537 posts #17

dont use the include(admob.php) code as gum says it states wot the problem is in the error.

use the admob code in one of your main files ie index or core if u use a lava edit script.

and most lava edits have the code already installed in core u just need to change the account code so it operates from your account not the persons whos script it was . .

hope that helps to sort you error

cobusbo Developer · 117 posts #18

The ads arent the problem the only problem I have is that the admob.php directory where it comes from must be changed to the main folder of my site and I cant get id edited correctly

strikingv Developer · 70 posts #19

nice logo. it suits admob. n beware thew may steal it. 😛 they r scaM

morency Senior · 488 posts #20

GumSlone wrote: Your account has been disabled for invalid activity or repeated policy violations. Some examples include recurring manual clicks or impressions, violation of our content policies which can be found here, robots, automated click and impression generating tools, third-party services that generate clicks or impressions such as pay-to-click, pay-to-surf, autosurf, and click-exchange programs, or any deceptive software. Please visit our Account Review form if you feel additional information would be valuable in explaining your situation.

is the default message... i think admob is now for publishers who make few bux per month/////lets write on every forum about admob ....

Unamos los corazones,hoy todos somos multicolores!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close