homepage Welcome to WebmasterWorld Guest from 54.196.196.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Why the following code doesnt work?
tnet




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

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

 

tnet




msg:4573490
 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.

jatar_k




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

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

gingir




msg:4574937
 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)
if(stristr($_SERVER['SERVER_NAME'],$domain))
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]

tnet




msg:4575633
 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]

jatar_k




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

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

tnet




msg:4576013
 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]

lucy24




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

<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.

tnet




msg:4576073
 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.

Thanks.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved