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>';
}
?>
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.
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”)
}
Could you also write a Javascript version of the script? I haven’t been able to find one anywhere.
So I wonder is there a way to make this work on blogger?
mark’s last blog post..Unsanitary