Welcome to WebmasterWorld Guest from 54.166.227.36

Forum Moderators: incrediBILL & martinibuster

Message Too Old, No Replies

AdSense for Mobile Woes

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

5+ Year Member



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.
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?
10:48 am on Jun 9, 2013 (gmt 0)

5+ Year Member



And how to do that?
11:09 am on Jun 9, 2013 (gmt 0)
11:11 am on Jun 9, 2013 (gmt 0)

5+ Year Member



I don't know anything about php at all
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 :)
5:57 pm on Jun 9, 2013 (gmt 0)

5+ Year Member



But if I use include I wont be able. to set a timeout
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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month