开发者

Replace an img src value based on a referring URL's query string

I have a Magento store and I would like to replace the src value of an img based on whether the referring URL contains a specific querystring or querystring value (adnetwork=as) and if not simply leave the image as it is.

Is this simple enough to do, I've searched everywhere for the answer, and even asked on various forums to no avail.

Here's what I have so far, seems like the correct syntax, just Firebug reports that it is unable to load the image URL, and it simply shows "". The paths are correct and have been tested.

<?php

// Path for default image source
$logo = $this->getSkinUrl('images/logo.gif');

// Get the referrer url from the $_SERVER array, or false if it's empty
$referrer = empty($_SERVER['HTTP_REFERER']) ? false : $_SERVER['HTTP_REFERER'];

// If the referrer exists
if($referrer) {

    // parse the url for the query
    $query_str = parse_url($referrer, PHP_URL_QUERY);

    开发者_JAVA技巧// If there's a query string
    if(!empty($query_str)) {
        // Parse it and put the array into $components
        parse_str($query_str, $components);

        // If the "adnetwork" component is set
        if(!empty($components['adnetwork'])) {
            // Set the $logo var to the adnetwork image source
            $logo = $this->getSkinUrl('images/logo-no-number.gif');
        }
    }
}

?>

<div class="header">

    <img class="shop24" src="<?php echo $this->getSkinUrl('images/shop-24.gif') ?>" alt="Shop Online 24 Hours a Day"/>

    <div class="shopping-bag"><?php echo $this->getChildHtml('topcart')?></div>

    <div id="fplogo"><a href="<?php echo $this->getUrl('') ?>" title="Sale Basins - Clickbasin.co.uk"><img src="<?php echo $logo; ?>" alt="Sale Basins - Clickbasin.co.uk" /></a></div>

    <img src="<?php echo $this->getSkinUrl('images/side_logo_promo.gif') ?>" alt="Promotion" class="side-logo-promo"/>

    <?php echo $this->getChildHtml('topMenu') ?>

    <?php //<?php echo $this->getLogoSrc() ?>

</div>

I hope you can help guys. Thanks.


Shouldn't you be simply echoing $logo? you are assigning the image to $logo but you never set anything to $logo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜