Home > PHP, Tips & Tricks > Change Adsense Publisher ID In Other Site With PHP and cURL

Change Adsense Publisher ID In Other Site With PHP and cURL

December 22nd, 2009 Admin Leave a comment Go to comments
Advertisement

This tutorial is actually a long time I write but only in the Indonesian language, and it is time to change it into English to be understood by more people.

Through the help of PHP and cURL, we will try to change the code from adsense publisher ID (adsense injection) which usually use the format “pub-1324123412341212“. 16 digits after the pub is the adsense code that will be changed into our publisher ID code. Here is a script that will be used:

 
<?php
 
    //define URL
    $open_url = 'http://blog.smileylover.com/all-about-bmw-news-luxury-cars';
 
    //define your adsense ID, without pub-
    $adsense_id = '1234123412341235';
 
    //open connection  
    $ch = curl_init();  
 
    //set the url, number of POST vars, POST data  
    curl_setopt($ch,CURLOPT_URL, $open_url);  
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);    
    $result = curl_exec($ch);  
    curl_close($ch); 
 
    //replace original adsense code
        $pattern    = '#google_ad_client = \"(.*)\"#';
        $out = preg_replace($pattern, 'google_ad_client = "pub-'.$adsense_id.'"', $result);
        $out = preg_replace('#google_ad_slot#','//google_ad_slot', $out);
        $out = preg_replace('#google_ad_channel#','//google_ad_channel', $out);
 
    echo $out;
 
?>

Please change the $open_url the target site that will be changed following codenya $adsense_id accordance with your publisher ID. Upload the script to your hosting course must support cURL. Open the script that has been uploaded via the browser and “view-source” on that page. Then you will find a publisher ID code has been changed according to what we write in the script! Happy earnings:)

Demo (built in shortened URL)

No related posts.

Categories: PHP, Tips & Tricks Tags:
  1. December 26th, 2009 at 13:29 | #1

    wew.. keren banget Gan salute.. btw ane numpang pertamaX boleh kan?

  1. No trackbacks yet.