Google AdSense allows mobile websites to monetize traffic by placing Google AdSense for Mobile Content targeted ads. However, when placing the PHP-based Google AdSense ad code for “All Phones” device type into PHP web pages of mobile sites, the following error message may appear, and log on Apache error log.

PHP Fatal error: Call to undefined function read_global() in wap/index.php on line 88

In PHP Google AdSense for Mobile Content code, there are several global variable declarations which require read_global function. The problem is that the read_global() function is only declared later in the AdSense code, and not before the lines of code which require the function. In some PHP implementation, a function has to be explicitly declared and loaded before the function is called.

To solve the PHP call to undefined function read_global() fatal error of Google AdSense for Mobile Content code, try to move the function declaration of read_global() to the top of the ad code block, i.e. above all the $GLOBALS[‘google’] lines. The function is declared in the following block of code:

function read_global($var) {
return isset($_SERVER[$var]) ? $_SERVER[$var]: '';
}

The PHP error should be solved by moving the function declaration to the top. However, websites which having this error may continue to face other undefined function errors for google_set_screen_res(), google_set_muid() and google_set_via_and_accept().

Likewise, just move the function declaration blocks to above the line where respective function is called, or simply move the line of code where function is called to below the function declaration block, will solve most errors.

For example,

function google_set_screen_res() {
$screen_res = read_global('HTTP_UA_PIXELS');
if ($screen_res == '') {
$screen_res = read_global('HTTP_X_UP_DEVCAP_SCREENPIXELS');
}
if ($screen_res == '') {
$screen_res = read_global('HTTP_X_JPHONE_DISPLAY');
}
$res_array = split('[x,*]', $screen_res);
if (sizeof($res_array) == 2) {
$GLOBALS['google']['u_w'] = $res_array[0];
$GLOBALS['google']['u_h'] = $res_array[1];
}
}
google_set_screen_res();

function google_set_muid() {
$muid = read_global('HTTP_X_DCMGUID');
if ($muid != '') {
$GLOBALS['google']['muid'] = $muid;
}
$muid = read_global('HTTP_X_UP_SUBNO');
if ($muid != '') {
$GLOBALS['google']['muid'] = $muid;
}
$muid = read_global('HTTP_X_JPHONE_UID');
if ($muid != '') {
$GLOBALS['google']['muid'] = $muid;
}
$muid = read_global('HTTP_X_EM_UID');
if ($muid != '') {
$GLOBALS['google']['muid'] = $muid;
}
}
google_set_muid();

function google_set_via_and_accept() {
$ua = read_global('HTTP_USER_AGENT');
if ($ua == '') {
$GLOBALS['google']['via'] = read_global('HTTP_VIA');
$GLOBALS['google']['accept'] = read_global('HTTP_ACCEPT');
}
}
google_set_via_and_accept();

Related Posts