Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Why the following code doesnt work?



8:05 am on May 13, 2013 (gmt 0)

$banners = array(
'' => '',
'' => '',
'' => '',
foreach ($banners as $domain => $banner) {
if(stristr($_SERVER['SERVER_NAME'], $domain)) {
echo $banner;


12:25 pm on May 13, 2013 (gmt 0)

For some reason, I can't get it to work. I have a folder with banners, and they need to be displayed on a website, depending on a domain name. Is there any way somebody could suggest me the code? Thank you.


2:24 pm on May 13, 2013 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

well, that code could work, though I would change it to

if(stristr($_SERVER['SERVER_NAME'], $domain) != false) {

but it could be something in your data and that is just a bunch of blanks. If that code is outputting nothing, then it's doing what it should be doing.

maybe a snippet with a bit of real data would help


12:11 pm on May 17, 2013 (gmt 0)

It works to me, my debug test

$_SERVER['SERVER_NAME'] = 'example.com';

$banners = array(
'example.org' => '1',
'example.com' => '2',
'example.net' => '3'

foreach($banners as $domain => $banner)
echo $banner;

2 was echoed.

Get rid of the last, in the array by the way

[edited by: tedster at 4:22 pm (utc) on May 17, 2013]
[edit reason] use example.com, not real domain names [/edit]


7:00 am on May 20, 2013 (gmt 0)

System: The following message was spliced on to this thread from: http://www.webmasterworld.com/php/4575631.htm [webmasterworld.com] by jatar_k - 10:16 am on May 20, 2013 <small>(est -8)</small>

I have a code that is suppose to display 55 different banners depending on a domain name, and for some reason it works only on the first five sites. I've checked everything one hundred times, and I am not sure why it does not work. The code outputs the code on a website, but there is no banners displayed.

[edited by: jatar_k at 6:21 pm (utc) on May 20, 2013]


6:20 pm on May 20, 2013 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

hey tnet,

what is different about the 6th site? if the first 5 work I would think the code should be ok and it more likely has something going on with the data


6:24 am on May 21, 2013 (gmt 0)

It looks like php is working correctly, since I get this code displayed on all sites:

<div class="banner">
<a href="http://some-domain-name.com/" rel="nofollow" target="_blank"><img scr="../banners/actor-name.gif" alt="website"></a></div>

Browsers also show an empty rectangle, an I can click on it to get directed to particular sites. The only issue is that the images don't show for most of the websites. For some reason the first 5 display correctly, and the rest (remaining 50) doesn't work. I checked the permissions, and the folder, and all the img files are set to 755. I have no idea why this doesn't work.

[edited by: tedster at 12:20 pm (utc) on May 21, 2013]
[edit reason] no links, please [/edit]


7:16 am on May 21, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

<img scr="../banners/actor-name.gif" alt="website">

Please say that was a typo. It would almost have to be, if it's all coming out of the same php and it sometimes works.

When it "doesn't work" does the browser display a little box or question mark, the way it does when it can't find an image? Or nothing at all?

Are all the banners identical? That is, same format, same dimensions in pixels, all in the same directory? And the originating code is all happening on the same page? The relative URL ../ made me uneasy, so it is good to double check.


10:03 am on May 21, 2013 (gmt 0)

Thank you. This is whats wrong. I figured it out a while ago. It was "img scr" instead of "src" in most of the code.


Featured Threads

Hot Threads This Week

Hot Threads This Month