How To Add a Custom Welcome Based on Referrer

Posted in PHP | By LGR | On September 17th, 2007

I recently added a little snippet of PHP to Video Rambler to welcome people that were coming from StumbleUpon with a custom welcome. The website recently got Stumbled again and one of the people that gave the site a thumbs up stated:

I only gave it thumbs up bc I’m wondering how they put that stumbleupon welcome message at the top…only shows if you stumble it.

Here is how I did it. I check the $_SERVER['HTTP_REFERER'] to see if it is one of the referrers I want to give a special welcome to. If it is then I simply echo some css to add some padding to the top of the screen and print out the custom welcome. This might not be fool proof, since some browsers do not pass the referrer, or people could fake the referrer, but it works quite well for StumbleUpon. You could make this more complicated and display a different message for more than just Stumblers, but those were the only people I was interested in at this time. I have been using it for a month and considering how well the website has been doing with StumbleUpon I think I will keep using it for a little while.

<?php
$allowed = Array('www.stumbleupon.com','stumbleupon.com');
$camefrom = array_change_key_case(parse_url($_SERVER['HTTP_REFERER']));
if (in_array($camefrom['host'],$allowed)) {
echo '<style type="text/css">body { padding-top: 25px; } </style>';
echo '<div style="position: absolute; top: 0; left: 0px; width: 100%; padding: 3px 15px 3px 15px; background-color:#ffffe1;">Welcome Stumbler! Hope you enjoy the site and it would be great if you would give a nice <a href="javascript:document.location.href = \'http://www.stumbleupon.com/submit?url=\'+ document.URL +\'&title = \'+document.title.replace(/%20/g,\'+\');">Thumbs Up!</a> Enjoy!</div>';
}
?>

Similar Posts:

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon
  • email
  • FriendFeed
  • Reddit
  • RSS
  • Twitter
  1. [...] and encourages them to subscribe to your feed. If you are not using WordPress, but you can run PHP consider adding a similar PHP script to welcome [...]

  2. [...] can edit the message to say what ever you want. If you are not using WordPress, but you can run PHP consider adding a similar PHP script to welcome [...]

  3. Mike Smith says:

    I’ve been wondering how to do this and am going to add it to my blog now. Thank you for posting the code. I appreciate it.

  4. [...] technical elbow grease. Ask your techie to help you with that. Technically inclined? Then check out this short tutorial and code [...]

  5. For non WP users, here’s another tutorial tapping into Google scripts, in face the whole script one adds is 11 lines long.

    http://www.quietaffiliate.com/dynamically-generate-users-location-on-landing-pages

    —– in case their sites goes down, here’s the code —–

    if (typeof(google.loader.ClientLocation.address.city) != null) {
    document.write(google.loader.ClientLocation.address.city
    +”, ”
    +google.loader.ClientLocation.address.region);
    } else {
    document.write(“Unknown location”)
    }

  6. Rob says:

    Could you also write a Javascript version of the script? I haven’t been able to find one anywhere.

  7. mark says:

    So I wonder is there a way to make this work on blogger?

    mark’s last blog post..Unsanitary

  8. LGR says:

    Interesting post. I will have to give that a try.

  9. LGR says:

    You know I did have a Javascript version at one time. I’ll see if I can find it and write a post about it. If you are using WordPress take a look at the WP Greet Box plugin. I have been happy with it on WordPress sites.

  10. LGR says:

    I had another request that was similar. I have an idea, just need to get some time to put it together and test it. Stay tuned, maybe I will get some time this weekend. Cross my fingers.

Leave a Reply

COMMENT


My Comment Policy: I moderate comments. Please be patient:

  • Spam will happily be destroyed.
  • Use your real name, not some keywords. Otherwise it will be destroyed.
  • Mean comments aren't necessary.
  • Lewd comments will be edited, I don't want my readers leaving because of offensive content.
  • Great debate, ideas, criticism and colorful commentary is always appreciated and approved!
«
»