I want a script that can display google ads, and linkable images on a rotator when a page is refreshed. I dont want it to be database driven and i dont want ti to be in javascript. I also dont want it on a timer. I know thats a lot of dont wants but id really appreciate any help
this is a simple one: <?php $a="<a href='link'><img src='image.jpg' align='center'></a>"; $b="<a href='link2'><img src='image2.jpg' align='center'></a>"; srand( microtime() * 1000000); $var = rand(1,2); switch($var){ case 1: $ads=$a; break; case 2: $ads=$b; break; } echo $ads; Code (markup): to put adsense in the above change the " into '
i know this is fairly simpl but i once had a script which i cant find aymore and it was much simpler than this
For the .Net version code: <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="ad.xml" /> ad.xml file: <Advertisements> <Ad> <ImageUrl>site1img1.jpg</ImageUrl> <NavigateUrl>http://www.site1.com</NavigateUrl> <Impressions>50</Impressions> </Ad> <Ad> <ImageUrl>site2img2.jpg</ImageUrl> <NavigateUrl>http://www.site2.com</NavigateUrl> <Impressions>75</Impressions> </Ad> </Advertisements> Impressions is the relative weightings so in this example ad2 would be shown 1.5 times more often
i dont have asp, ive settled for a script that can use javascript however it needs to be able to accept google adsense, cheers for any help
In the original post you say you don't want JavaScript, but now you say you'll settle for JavaScript? Which one is it? What language is running your website? HTML, PHP, Perl...?
html and php, and i changed my mind because originally i didt want js as a lot of people have it disabled, however now i realise that adsense actually uses js so it doesnt really matter
how would i edit that in order for it to have adsense? do i change all of <a href='link'><img src='image.jpg' align='center'></a> to my adsense cod or everything but the a href and /a?
Basically you want to set the $a and $b variables to be the actual code you want to be displayed. In this case he simply has links, but you can change this to AdSense or whatever code you want.
i promise im not being lazy im just really not good wth code could you please put this where it needs to be for both of the different adsense accounts please? <script type="text/javascript"><!-- google_ad_client = "pub-00000000"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; google_ad_channel = ""; google_color_border = "666666"; google_color_bg = "666666"; google_color_link = "ffffff"; google_color_text = "ffffff"; google_color_url = "f29935"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
You need to place that code inside of the variable, but be sure to escape the ". If you're not sure how to do that then search Google.
ive tried it, it shows the first adsense, but when i refresh it doesnt hve the secod lot :s this is the code i was using, i jus put it in a simple page 1st <html> <head></head><body><?php $a="<script type="text/javascript"><!-- google_ad_client = "pub-00000000"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; google_ad_channel = ""; google_color_border = "666666"; google_color_bg = "666666"; google_color_link = "ffffff"; google_color_text = "ffffff"; google_color_url = "f29935"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>"; $b="<script type="text/javascript"><!-- google_ad_client = "pub-00000022200"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; google_ad_channel = ""; google_color_border = "666666"; google_color_bg = "666666"; google_color_link = "ffffff"; google_color_text = "ffffff"; google_color_url = "f29935"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>"; srand( microtime() * 1000000); $var = rand(1,2); switch($var){ case 1: $ads=$a; break; case 2: $ads=$b; break; } echo $ads; </body></html> PHP:
the code simply selects a random ad and by chance when u refreshed it selected the same ad again try refreshing it more. it is based on a probability and if u refresh 100 times and record ur observations then it will come to around 50-50 each.. it is NOT EXACT 50% ------------ also i think u forgot to close the php at the end .. place this ?>
ok sorry i did not look at the code earlier. i am posting this code now. this should work <html> <head></head><body><?php $a='<script type="text/javascript"><!-- google_ad_client = "pub-00000000"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; google_ad_channel = ""; google_color_border = "666666"; google_color_bg = "666666"; google_color_link = "ffffff"; google_color_text = "ffffff"; google_color_url = "f29935"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; $b='<script type="text/javascript"><!-- google_ad_client = "pub-00000022200"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; google_ad_channel = ""; google_color_border = "666666"; google_color_bg = "666666"; google_color_link = "ffffff"; google_color_text = "ffffff"; google_color_url = "f29935"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; srand( microtime() * 1000000); $var = rand(1,2); switch($var){ case 1: $ads=$a; break; case 2: $ads=$b; break; } echo $ads; ?> </body></html> Code (markup):
MAJOR MISTAKE IN YOUR CODE: you have to escape your quotes. ex: I want to take <font color="blue"> and put that into a javascript string. I would make it into: $a="<font color='blue'>"; so I would take my double quotes and make them into single quotes.
i do not think ur code will work because javascript will take ' and " differently. in the above code that i have posted i have rectified the error because php takes " and ' same
I was looking in the wrong area- my bad instead of replacing quotes with ' try /" and it should escape them. it might be \" though, I can't remember which way is which. pretty sure it's the right one.