Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow How can I randomize a google-adsense banner and an image ad

    Hello,

    I want to randomly display my adwords banner and a banner hosted on my site.

    Is there any way to do this?

    Here is what the adsense looks like:
    Code:
    <script type="text/javascript"><!--
    google_ad_client = "pub-9713982568167945";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel ="";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    and the banner is: http://www.thepartylive.com/banners/BANNER468X60-2.gif


    Basically I just want a script, similar to a random image script to alternative between these two and possibly more in the future. Any idea how I can do this?

    My site for reference: http://www.volconvo.com

    Thank you!

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    should be real easy in PHP:
    PHP Code:
    $arr_images = array('<script type="text/javascript"><!--
    google_ad_client = "pub-9713982568167945";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel ="";
    //--></script>
    <script type="text/javascript"'
    '<img src="http://www.thepartylive.com/banners/BANNER468X60-2.gif" alt="whatever" width="120" height="67" />')
    echo 
    array_rand($arr_images); 
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey thanks for trying,

    I am getting a line 2 char 8 error

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is that a javascript error? check the generated html-source in your browser --> maybe you need to add linebreaks in the javascriptcode. like this
    PHP Code:
    $arr_images = array('<script type="text/javascript"><!--'"\n" 
    'google_ad_client = "pub-9713982568167945";'"\n" .
    'google_ad_width = 728;'"\n" 
    'google_ad_height = 90;'"\n" 
    'google_ad_format = "728x90_as";'"\n" 
    'google_ad_type = "text";'"\n" 
    'google_ad_channel ="";'"\n" 
    '//--></script>'"\n" 
    '<script type="text/javascript"'"\n" .
      
    'src="http://pagead2.googlesyndication.com/pagead/show_ads.js">'"\n" .
    '</script>'"\n"'<img src="http://www.thepartylive.com/banners/BANNER468X60-2.gif" alt="whatever" width="120" height="67" />'
    echo 
    array_rand($arr_images); 
    what i was trying to explain, is that you just need to have this PHP code

    $arr_images = array('html-source for option1', 'html-source for option2','html-source for option3');
    echo array_rand($arr_images);
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    yea

    this php code should very easily work. It's definately the way to go

  • #6
    Regular Coder
    Join Date
    Oct 2002
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree but I cannot insert it into my header template, which is where is needs to go...only into the .php file. I would assume puting it in my .global.php would work but how do I reference it from that template?

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Another problem with the Javascript example is that the </script> in the code will terminate the Javascript early. Change it to <\/script> to fix that problem.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CeeN
    I agree but I cannot insert it into my header template, which is where is needs to go...only into the .php file. I would assume puting it in my .global.php would work but how do I reference it from that template?
    without knowing your code for these pages + your filestructure, we can't really advice you on that.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    Regular Coder
    Join Date
    Oct 2002
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah..I am trying to insert it into a vbulletin header template

  • #10
    Regular Coder
    Join Date
    Oct 2002
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured out that you can insert it into a vbulletin template called php_include like this:

    Code:
    ob_start();
    require("http://www.volconvo.com/googlerandom.php");
    $arr_images = ob_get_contents();
    ob_end_clean();
    The result on my page though when I reference $arr_images is:
    $arr_images = array(''. "\n" . '
    Any idea?


  •  

    Posting Permissions

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