ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Show certain content depending on url

December 21, 2011 5:50pm

Subscribe [2]
  • #1 / Dec 21, 2011 5:50pm

    rbboyl

    38 posts

    One of my clients is trying to show a different phone number when a visitor hits their EE site inbound from Yelp. 

    When someone comes into the site coming from Yelp, they want a different phone number to show at the top of the website.

    Is there some way to do this where they can provide a unique url on Yelp for their website (ie http://www.sampledomain.com/yelp), but still showing the full original website just with a different phone number?

    I know you can use conditionals to detect the last segment and display different content, but the challenge seems to be links within the site.  Would I have to then add “yelp” to the end of every link for this to work?  I guess this method would also mess up templates that use the last_segment for other purposes.

    Any help is much appreciated!

  • #2 / Dec 22, 2011 4:28pm

    Dan Decker

    7338 posts

    Hi rbboyl,

    What need in this case is a way to detect the $_SERVER[‘HTTP_REFERER’]

    I looked on Devot://ee for something that might let us avoid using PHP, and didn’t see anything right away.
    In PHP you would use something similar to this:

    <?php
    if ($_SERVER['HTTP_REFERER'] == 'http://www.sampledomain.com/yelp')
    {
      {alternate_phone}
    } else {
     {standard_phone}
    }

    You would need to enable PHP in the template and use that inside the channel entries tags that contains your contact info, or you could store those in a Global Variable.

    Let me know if you have any other questions.

  • #3 / Dec 22, 2011 4:59pm

    rbboyl

    38 posts

    Thanks for your help Dan.  In your sample code, are {alternate_phone} and {standard_phone} variables that are being set?

    What if someone clicks off the landing page and Yelp is no longer in the url?  Will {alternate_phone} or {standard_phone} carry to other pages?

  • #4 / Dec 23, 2011 5:00pm

    Sean C. Smith

    3818 posts

    rbboyl,

    alternate_phone and standard_phone would be variables you set in global variables or you could just hard code them in. You will probably need to add an echo to the code like this:

    <?php
    if ($_SERVER['HTTP_REFERER'] == 'http://www.sampledomain.com/yelp')
    {
      echo "{alternate_phone}";
    } else {
     echo "{standard_phone}";
    }  
    ?>

    That variable would not carry over to a new page unless you assign it to a php variable and then create a session for it.

    Sean

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases