Dear Friends, I need some help about Random Ads Rotation.. Actually I need a “PHP Random Add Rotator Script†for my Site… A Script that should work with out MY SQL…. And maximum numbers of Adds should be randomly rotated in that script. I am waiting Regards Omar (www.pakdes.com)
$Ad[0] = '<a href="http://www.site.com" TARGET="_blank">Site 0</a>'; $Ad[1] = '<a href="http://www.site1.com" TARGET="_blank">Site 1</a>'; $Ad[2] = '<a href="http://www.site2.com" TARGET="_blank">Site 2</a>'; $Weight[0]=3; $Weight[1]=3; $Weight[2]=3; $sum =0; for($i=0;$i<count($Weight);$i++) $sum+=$Weight[$i]; $ShowAd = rand(0, $sum - 1); for($i=0;$i<count($Weight);$i++) { if($ShowAd<=$Weight[$i]) { $ShowAd=$i; break; } else $ShowAd-=$Weight[$i]; } echo $Ad[$ShowAd]; PHP:
There are far more advanced systems than my script but if you just want to display adverts and maybe display some more than others without using a database or tracking views or clicks then this is all you need.
Thanks for this CODE, tell me one thing.. that should a add the "Add Code" in Ad[0], Ad[1], Ad[2]?? Or I can add more then 3 Ads? If so tell me HOW? Lets suppose I want to insert 10 Ads in this code then? Waiting
looks like you keep adding $Ad[x] = '<a href="http://www.site2.com" TARGET="_blank">Site 2</a>'; and $Weight[x]=3; until you get to 10
Make sure if you add more adverts you specify the weight of the adverts as well eg $Ad[0] = '<a href="http://www.site.com" TARGET="_blank">Site 0</a>'; $Ad[1] = '<a href="http://www.site1.com" TARGET="_blank">Site 1</a>'; $Ad[2]= '<a href="http://www.site2.com" TARGET="_blank">Site2</a>'; $Ad[3]= '<a href="http://www.site2.com" TARGET="_blank">Site2</a>'; $Weight[0]=3; $Weight[1]=3; $Weight[2]=3; $Weight[3]=3; PHP: etc. If you are still having problems post your source code.
Dear Really its not working.. Ihave tried many times but not working yet... can you check by your self? Okay let me give u the code of 2 Diff Adv. 1 is :+++++++++++++++++++++++++++++++++++++++++++ <!--- start of focusIN code ---> <script language="JavaScript"> <!-- var now = new Date(); var uaid = now.getTime() % Math.floor(8640000 - Math.random()*1000); document.write('<scr'+'ipt src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hjj&rw=468&rh=60&urlid=1&cv=220&uid=' + uaid + '" ></scr'+'ipt>'); //--> </script> <noscript> <iframe allowTransparency="true" src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hhn&rw=468&rh=60&urlid=1&cv=220&uid=1" width=468 height=60 frameborder=0 marginheight=0 marginwidth=0 scrolling="no"> <a href="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=cin&rw=468&rh=60&urlid=1&cv=220&uid=1" target="_top"><img src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hin&rw=468&rh=60&urlid=1&cv=220&uid=1" alt="Click here to visit our sponsor" width=468 height=60 border=0></a> </iframe> </noscript> <!--- end of focusIN code ---> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2nd is++++++++++++++++++++++++++++++++++++++++++++++++++++ <!-- PRECISIONCLICK.COM 2006 (C) --> <!-- Ad Format: 468x60 --> <script language="javascript"><!-- var d=new Date();var ccb=(d.getTime()%8673806982)+Math.random();document.write('<scr'+'ipt language="javascript" src="http://servedby.precisionclick.com/midas/?src=pub&site=417&adfmt=6&ccb='+ccb+'"></scr'+'ipt>'); //--></script><noscript><iframe src=src="http://servedby.precisionclick.com/midas/?typ=1&pub=1&site=417&adfmt=6" width="468" height="60" marginwidth="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe></noscript> ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Now please creat a PROOF of Rendom Rotation of Above TWO AD CODES... Waiting Regards
<?php $Weight[0]=3; $Weight[1]=3; $sum =0; for($i=0;$i<count($Weight);$i++) $sum+=$Weight[$i]; $ShowAd = rand(0, $sum - 1); for($i=0;$i<count($Weight);$i++) { if($ShowAd<=$Weight[$i]) { $ShowAd=$i; break; } else $ShowAd-=$Weight[$i]; } if($ShowAd=="1"){ ?> ?><!--- start of focusIN code ---> <script language="JavaScript"> <!-- var now = new Date(); var uaid = now.getTime() % Math.floor(8640000 - Math.random()*1000); document.write('<scr'+'ipt src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hjj&rw=468&rh=60&urlid=1&cv=220&uid=' + uaid + '" ></scr'+'ipt>'); //--> </script> <noscript> <iframe allowTransparency="true" src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hhn&rw=468&rh=60&urlid=1&cv=220&uid=1" width=468 height=60 frameborder=0 marginheight=0 marginwidth=0 scrolling="no"> <a href="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=cin&rw=468&rh=60&urlid=1&cv=220&uid=1" target="_top"><img src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hin&rw=468&rh=60&urlid=1&cv=220&uid=1" alt="Click here to visit our sponsor" width=468 height=60 border=0></a> </iframe> </noscript> <?php } elseif($ShowAd=="2") { ?> <!-- PRECISIONCLICK.COM 2006 (C) --> <!-- Ad Format: 468x60 --> <script language="javascript"><!-- var d=new Date();var ccb=(d.getTime()%8673806982)+Math.random();document.write('<scr'+'ipt language="javascript" src="http://servedby.precisionclick.com/midas/?src=pub&site=417&adfmt=6&ccb='+ccb+'"></scr'+'ipt>'); //--></script><noscript><iframe src=src="http://servedby.precisionclick.com/midas/?typ=1&pub=1&site=417&adfmt=6" width="468" height="60" marginwidth="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe></noscript> <?php } else { } ?> PHP:
Dear DAV nice effort but its not workinng... please check it by ur self, have u checked before pasting here?
<?php $Ad[0] =1; $Ad[1] =2; $Weight[0]=3; $Weight[1]=3; ; $sum =0; for($i=0;$i<count($Weight);$i++) $sum+=$Weight[$i]; $ShowAd = rand(0, $sum - 1); for($i=0;$i<count($Weight);$i++) { if($ShowAd<=$Weight[$i]) { $ShowAd=$i; break; } else $ShowAd-=$Weight[$i]; } if($Ad[$ShowAd]=="1"){ ?> <!--- start of focusIN code ---> <script language="JavaScript"> <!-- var now = new Date(); var uaid = now.getTime() % Math.floor(8640000 - Math.random()*1000); document.write('<scr'+'ipt src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hjj&rw=468&rh=60&urlid=1&cv=220&uid=' + uaid + '" ></scr'+'ipt>'); //--> </script> <noscript> <iframe allowTransparency="true" src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hhn&rw=468&rh=60&urlid=1&cv=220&uid=1" width=468 height=60 frameborder=0 marginheight=0 marginwidth=0 scrolling="no"> <a href="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=cin&rw=468&rh=60&urlid=1&cv=220&uid=1" target="_top"><img src="http://focusin.ads.targetnet.com//ad/id=pakdes.com&opt=hin&rw=468&rh=60&urlid=1&cv=220&uid=1" alt="Click here to visit our sponsor" width=468 height=60 border=0></a> </iframe> </noscript> <?php } else { ?> <!-- PRECISIONCLICK.COM 2006 (C) --> <!-- Ad Format: 468x60 --> <script language="javascript"><!-- var d=new Date();var ccb=(d.getTime()%8673806982)+Math.random();document.write('<scr'+'ipt language="javascript" src="http://servedby.precisionclick.com/midas/?src=pub&site=417&adfmt=6&ccb='+ccb+'"></scr'+'ipt>'); //--></script><noscript><iframe src=src="http://servedby.precisionclick.com/midas/?typ=1&pub=1&site=417&adfmt=6" width="468" height="60" marginwidth="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe></noscript> <?php } ?> PHP: Here you go, fully tested. Let me know your paypal address so I can send the bill..........
Sir GGGGGGGGGGGGGGGGGG, its not workiinnnnnnnnnngggggggggggggggggggg......... I think 1st I have to pay then it'll be avaialable Dear check it again!! Nothing is available in DISPLAY!!
There is nothing wrong with the php code (tested it first) so the only problem could be with the JS maybe. Try replacing the 2 adverts with text saying "Advert 1" and "Advert 2" and let me know what you get. Are you putting the code in a proper page or just using the script on its own?
Dear Dav, I have checked it by replacing some thing like..... ABCD (Replacing 1st Ad Code) and EFGH (by replacing 2nd Ad Code) by replacing with these TAXT WORDS, its really working!!! without any trouble, but when I pust AD CODES into this script as you PUT my given CODES, its not working!! It is not possible if we save these code in different HTML Files & we should put only FILE NAME i.e "ABC_CODE.HTML" and this code pick AD CODE from those files? Is it possible? Regards & once again really I am very thankful for all these efforts for me
There must be a problem with the adverts you are including I think. Try putting each advert on its own in the page instead of using the script to see what the problem is.
Dear Dav, I have checked these ADD CODES on my site... you can check this site : www.pakdes.com / www.pakdes.com/forum It will work if we include any HTML File? Regards
If you liked PAN, you will like Max Media Manager even more! Both require MySQL, but it's worth it if you can find a database somewhere.
I too am having problems. Maybe its something really obvious that I am missing because I am a newbie. Here is the code for my webpage: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $Ad[0] = '<a href="http://www.site.com" TARGET="_blank">Site 0</a>'; $Ad[1] = '<a href="http://www.site1.com" TARGET="_blank">Site 1</a>'; $Ad[2] = '<a href="http://www.site2.com" TARGET="_blank">Site 2</a>'; $Weight[0]=3; $Weight[1]=3; $Weight[2]=3; $sum =0; for($i=0;$i<count($Weight);$i++) $sum+=$Weight[$i]; $ShowAd = rand(0, $sum - 1); for($i=0;$i<count($Weight);$i++) { if($ShowAd<=$Weight[$i]) { $ShowAd=$i; break; } else $ShowAd-=$Weight[$i]; } echo $Ad[$ShowAd]; ?> </body> </html> HTML: And all I get is a blank page. Here's the page: http://www.yes2.us/Untitled-2.htm Maybe I shaould start a new topic for this, but, if I can get this to work, I would like to use it to randomly redirect to different weblinks, but I'm not sure how to modify it to do that.