Ocak 1, 2021

Rastgele Banner Kodu

Javascript

<script>
image0="/banners/banner1.gif";
href0="/default.asp";
alt0="W3Schools.com";

image1="/banners/banner2.gif";
href1="http://www.deneme.com/html/html_reference.asp";
alt1="HTML Reference";

image2="/banners/banner3.gif";
href2="http://www.deneme.com/xhtml/default.asp";
alt2="ASP Free";

len=3;

now=new Date();
now=now.getSeconds();
rnd=now%len;

image=eval("image"+rnd);
href=eval("href"+rnd);
alt=eval("alt"+rnd);

document.write("<a href='" + href + "'>");
document.write("<img src='" + image + "' alt='" + alt + "'></a>");
</script>

PHP

<?php
$advert = array(); 
  $advert[] = '<a href="#">Banner 1</a>';
  $advert[] = '<a href="#">Banner 2</a>';
  $advert[] = '<a href="#">Banner 3</a>';
shuffle($advert); 
echo $advert[0];
?>

yada

<?php
$bannerAd[1] = 'code for ad 1';
$bannerAd[2] = 'code for ad 2';
$bannerAd[3] = 'code for ad 3';
$bannerAd[4] = 'code for ad 4';
$bannerAd[5] = 'code for ad 5';

$adCount = count($bannerAd);
$randomAdNumber = mt_rand(1, $adCount);
echo $bannerAd[$randomAdNumber];
?>

gösterim yüzdesini belirleme

<?php
$bannerAd[1] = 'code for ads 1 - %70';
$bannerAd[2] = 'code for ads 2 - %20';
$bannerAd[3] = 'code for ads 3 - %10';

//10 üzerinden bir oran belirleyelim.
$random = array(1,1,1,1,1,1,1,2,2,3);
echo $bannerAd[$random[array_rand($random,1)]];
?>

uygulama

< ? php
include 'banner.php';  // Works.
? >

 

You may also like...

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir


Fatal error: Uncaught Error: Call to undefined method Ressio_HtmlOptimizer_Dom_Element::addChild() in /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/htmloptimizer/dom.php:182 Stack trace: #0 /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/plugin/widgets/widgets.php(66): Ressio_HtmlOptimizer_Dom->appendScriptDeclaration('!function(e,t,n...', Array, Object(Ressio_HtmlOptimizer_Dom_Element)) #1 /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/plugin/widgets/widgets.php(151): Ressio_Plugin_Widgets->injectJsLoader(Object(Ressio_HtmlOptimizer_Dom), Object(Ressio_HtmlOptimizer_Dom_Element)) #2 /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/dispatcher.php(117): Ressio_Plugin_Widgets->onHtmlIterateTagSCRIPTBefore(Object(Ressio_Event), Object(Ressio_HtmlOptimizer_Dom), Object(Ressio_HtmlOptimizer_Dom_Element)) #3 /home/altiltoy/siteler/serdarakyol.com/wp-content in /home/altiltoy/siteler/serdarakyol.com/wp-content/plugins/psn-pagespeed-ninja/ress/classes/htmloptimizer/dom.php on line 182