2007年11月8日木曜日

モバイル向け AdSense

携帯サイトにAdSenseを張ろうとすると、
どうやら利用しているサーバーでは外部URLはrequireでエラーが出る模様。
というか、PHPでデフォルト設定らしい。
で、サーバー設定は変更不可と言う事なのに、
解決しないといけないというので、以下のように改変してみた。


$tmpfile = "/tmp/googlead.php";

$file = file_get_contents('http://pagead2.googlesyndication.com/pagead/show_ads.php');
$fp = fopen($tmpfile, "w");
fwrite($fp,$file);
fclose($fp);

$GLOBALS['google']['ad_type']='text';
$GLOBALS['google']['channel']='xxxxxxxxxx';
$GLOBALS['google']['client']='xxxxxxxxxx';
$GLOBALS['google']['format']='mobile_single';
$GLOBALS['google']['https']=$_SERVER['HTTPS'];
$GLOBALS['google']['host']=$_SERVER['HTTP_HOST'];
$GLOBALS['google']['ip']=$_SERVER['REMOTE_ADDR'];
$GLOBALS['google']['markup']='xhtml';
$GLOBALS['google']['oe']='utf8';
$GLOBALS['google']['output']='xhtml';
$GLOBALS['google']['ref']=$_SERVER['HTTP_REFERER'];
$GLOBALS['google']['url']=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$GLOBALS['google']['useragent']=$_SERVER['HTTP_USER_AGENT'];

require($tmpfile);



要するに、外部ファイルを一度手元に保存して、そちらをrequireするようにしてみた。
中身読んで、http://pagead2.googlesyndication.com/pagead/ads?
に直接取得しに行こうかとも考えたけど、それはやめておいた。

どうかGoogleの中の人がこれを見ていても、これくらいは見逃してください。

0 件のコメント: