0

I have some ads in a PHP file, which I simply include. (4 Images in an array and a little array_rand function).

In Chrome and Firefox, the PHP output/images don't show up in HTML. The expected HTML output is simply not there nor do I get an error message.

I have also tried to simply show 1 raw HTML-Tag/Image instead of the random function. Nothing in Chrome and Firefox - Opera, Safari and IE show the ads the way they should.

I have never encountered such an weird behaviour, since I don't get any PHP errors.

Page/error can be seen here: http://beta.com4tires.de/partner-werden.php

<?php

$input = array(
'<a href="http://www.advanti-racing.de/pages/deutsch/produkte/turba.php" target="_blank"
  class="bannerLink"><img src="img/ads/Advanti-Turba.jpg" width="160" height="600"      alt="Advanti Racing - Turba Ad" /></a>',
'<a href="http://www.achilles-reifen.de/pkw-atr-sport-2" target="_blank" class="bannerLink"><img src="img/ads/Achilles-ATR-Sport-2.jpg" width="160" height="600" alt="Achilles Radial - ATR-Sport 2 Ad" /></a>',
'<a href="http://www.enkei.de" target="_blank" class="bannerLink"><img src="img/ads/Enkei-Izumo.jpg" width="160" height="600" alt="Enkei Tuning - Izumo Ad" /></a>',
'<a href="http://www.oxxo-wheels.de/pages/deutsch/produkte/pondora.php" target="_blank" class="bannerLink"><img src="img/ads/OXXO-Pondora.jpg" width="160" height="600" alt="OXXO Alloy Wheels - Turba Ad" /></a>',
'<a href="http://www.com4wheels.de/crossover.html" target="_blank" class="bannerLink"><img src="img/ads/Com4Wheels-Crossover.jpg" width="160" height="600" alt="Com4Wheels - Crossover Ad" /></a>'
);
');

$rand_keys = array_rand($input);
?>
<div class="barBox">
<h2><i class="fa fa-bell"></i>Werbung</h2>
<?php echo $input[$rand_keys]; ?>  
Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
  • Can you post the images variable ? Are they stored as paths ? – hopsoo Feb 27 '14 at 07:49
  • 1
    The ads is there, I think there are some adblock plugins with your browsers. – Andrew Feb 27 '14 at 07:52
  • When in PHP and debugging, `var_dump` is a much better way of seeing what any variable is, both type and contents. – Roberto Feb 27 '14 at 07:53
  • Thank you all, I'll check the output by var_dump and give some feedback. –  Feb 27 '14 at 07:54
  • 2
    I can't believe I'm blocking my own ads.. this is so embarrassing.. delete this post.. jeezuz.. Thank you Andrew.. I should sell Hamburgers.. –  Feb 27 '14 at 07:57
  • @user2424222 Happens to the best of us. I'll come buy a hamburger once I've finished at my new day job as a postman. That's the career change *I* always dream about at moments like that, anyway ;) – Matt Gibson Feb 27 '14 at 08:03
  • Members of Stack Exchange will get Hamburgers for free. Such a great community - all of you :-) –  Feb 27 '14 at 08:18
  • This has just brightened my morning, thanks for the laugh. :) – The Blue Dog Feb 27 '14 at 08:36

1 Answers1

1

At default, array_rand picks one key from the given array. So $rand_keys is in your specific case is just one key randomly selected from the $input array. As I can see on your site (given link), there is one ad showing up which is expected. array_rand can have a second argument, which is the required number of keys from the given array.

php.net/array_rand

<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
hattila
  • 490
  • 5
  • 13