SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adsense in External PHP File?

    I'll make this post short,

    I want to place my adsense code in to an external PHP file. I then need to know how I get the adsense information from the php file into my websites php files.

    I also want the color of the adsense link (the main header of the ad) to change between 4 colors randomly.

    Could someone help me out here? I only know basic php so if someone can tell me how I can do this, that would be great

    Cheers!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you save your AdSense code into a file named "adsense.php", then in your webpages you'd write <?php include("adsense.php"); ?> to insert the contents of the file.

    As for switching link color:
    adsense.php
    PHP Code:
    <?php
    //whatever colors you want
    $colors = array("000000""0000ff""ff0000""00ff00"); 

    //generate a random number from 0 to 3 (4 values)
    $randval rand(0,3); 

    //get the color from the array by the random key
    $linkcolor $colors[$randval]; 
    ?>
    <script type="text/javascript"><!--
    google_ad_client = "pub-9095657276960731";
    google_ad_width = 160;
    google_ad_height = 600;
    google_ad_format = "160x600_as";
    google_ad_type = "text_image";
    google_ad_channel ="";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "<?php echo $linkcolor?>";
    google_color_url = "008000";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>

  3. #3
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but do I put "<?php include("adsense.php"); ?>" in the ehad of the document. If so, how do I then choose the spot on the page I want the adsense ads?

    Cheers!

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, you put it where you want the ad to be.

  5. #5
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, sweet.

    Thanks heaps for that

    Cheers!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •