Tutorial: Use PHP to display exclusive content for Google Visitors

While browsing through my visitor referrals this morning, I noticed that a large number of unique visitors are making their way over to my little site from Google Images. A quick look at bandwidth usage shows that the majority of visitors are just looking for images to leech for MySpace profiles, etc, which I don’t mind so long as it doesn’t get out of hand.

So, I thought about it for awhile. I have several thousand visitors a month showing up on my “artwork” page and they’re nearly all coming from the same place.

What if I could have a message that would be shown only when a visitor arrived from Google Images? That might be something worth playing around with ;).

Well, having seen similiar things before, I knew it was possible. After a bit of digging and a tip in the right direction, compliments of performancing.com, I found a solution.

First, let’s see it in action. Visit my artwork page and you’ll see it as the average visitor to jonathanwold.com will see it.

Next, head on over to Google and do an image search for “blue flames“, one of my more popular search terms. Depending on your country, the name “Jonathan” should be somewhere in the top 10 in blue flames. Click on it and you’ll see the message for Google Images visitors. (Don’t see it? Let me know ;)

Alrighty, now for the code! Copy and then paste the code below into notepad (or similiar plain text editor) to clear any formatting tags, then use on a PHP page and enjoy!



<?php

// This handy little script checks to see if visitors
// are arriving from Google Images and, if so,
// displays an alternate message. Credit to
// performancing.com for the tip! : )

if (stristr(getenv('HTTP_REFERER'),"images.google.com"))
{
?>

Your Message Here - You can use HTML ;)

<?php
}
?>

And there you have it. Paste the code into the PHP page you wish to use it on and modify the HTML section as appropriate. In my particular situation, I included a CSS styled DIV tag to display my visitor notice. You can change the “referer” from images.google.com to whatever you’d like. Use your imagination :). Alrighty, and that’s that for this morning! Enjoy and if you have any questions, comments, or suggestions, add them in the comments below or send me an email.

Have a wonderful rest of the day! : )

-Jonathan

This entry was posted on Sunday, April 29th, 2007 at 8:08 am and is filed under Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

And, if you like what you've read, be sure to Share This

2 Responses to “Tutorial: Use PHP to display exclusive content for Google Visitors”

Jun 18

Stuart Meldrum wrote...

Thanks, this is exactly the sort of script I was looking for. You don’t mind if I use it do you? I’ve credited you in the script.

Stuart

5:15 AM

Jun 27

Jonathan Wold wrote...

Take it away Stuart.. I’d be in a whole lot of trouble if not for the contributions that other developers have been willing to share over the years :).

Keep up the good work my friend,

-Jonathan

4:56 PM

Leave a Friendly Reply

The Author

Jonathan Wold is a 21 year old Internet Entrepreneur who believes that faith and works are inseparable. Here you'll find examples of faith, web design, niche marketing, CSS, Wordpress, and more.

Pages of Interest

Services

Post Categories

Looking for more?

Extra Goodness

Add to Technorati Favorites