Forum Moderators: martinibuster

Message Too Old, No Replies

AdSense for Mobile Woes

         

yaashul

1:00 pm on Jun 8, 2013 (gmt 0)

10+ Year Member Top Contributors Of The Month



Google Mobile ads for PHP based server side scripting have function

$google_ad_handle = @fopen(google_get_ad_url(), 'r');
if ($google_ad_handle) {
while (!feof($google_ad_handle)) {
echo fread($google_ad_handle, 8192);
}
fclose($google_ad_handle);
}


Now most of the hosting provider close(disable) php fopen function. There is a work around to achieve the same thing. Just replace the code with this


function curl_get_contents($url, $timeout=60) {
$timeout = abs((int)$timeout);
$curl = curl_init();
$opts = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => $timeout
);

curl_setopt_array($curl, $opts);
$result = curl_exec($curl);
if($result === false){
user_error(curl_error($curl));
return false;
}
$response = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($response != 200){
user_error("Received HTTP response of $response.");
}
return $result;
}

$url= google_get_ad_url();
$contents = curl_get_contents($url);
echo $contents;



But My question is Does it break ADSENSE Policy?

I didn't write this code. I found it on a website.

leadegroot

10:11 am on Jun 9, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does it break Adsense Policy?

No, because Adsense TOS governs _what_ you serve, not _how_ you serve it.

But surely, you would use an include or require rather than an fopen or a curl?

yaashul

10:48 am on Jun 9, 2013 (gmt 0)

10+ Year Member Top Contributors Of The Month



And how to do that?

leadegroot

11:09 am on Jun 9, 2013 (gmt 0)

yaashul

11:11 am on Jun 9, 2013 (gmt 0)

10+ Year Member Top Contributors Of The Month



I don't know anything about php at all

leadegroot

11:27 am on Jun 9, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, best to get reading then. php.net is definitive and excellent :)

yaashul

5:57 pm on Jun 9, 2013 (gmt 0)

10+ Year Member Top Contributors Of The Month



But if I use include I wont be able. to set a timeout

leadegroot

11:47 pm on Jun 9, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



fopen and curl are used to include files from other sites/hosts.
It would be inefficient and odd to have your own code on another host. Put it locally.
'include' doesnt need a timeout, it isn't subject to delays.