Is it possible to change the template based on where a user came from?

For example, I have a user that is looking at candles on BCcandle.com and they want to purchase a candle. They click the "BUY NOW" button and they are taken to QSDirectusa.com which sells the candles. I want the template on QSDirectusa.com to change and be branded to BCcandle.com, only if the traffic comes from that site. I would simply change the template if we were using only one. But I need to have multiple templates that can be changed 'on the fly' for one cart.

I know how to do all of the html and css to make the stylesheet.

I need some direction on how to change, within zencart, the page template based on where traffic came from .

I have some code written that will perform an action if a user has come from a certain URL:
PHP Code:
<?php
/* To store the page the user came from */
$referredURL $_SERVER['HTTP_REFERER'];
if(
$referredURL=="http://xxxxxxx.com"){
    
//perform command
}
?>
Thanks in advanced.