Are you a Google Analytics enthusiast?
Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE!

www.CustomReportSharing.com
From the folks who brought you High Rankings!
More SEO Content
Methods For Showing Specific Content Based On Referrer
#1
Posted 04 July 2009 - 11:35 AM
Mainly, I was reading up on Google's First Click Free program where you'd need to do this.
The gist of the program is that you can show password protected or registration protected content to Googlebot without them having to register, but you must also show the same content to the user if they come through a Google search.
Which means you have to be able to know that when the referrer of the content is Google, that the user sees the actual content Google indexed, not a page that says they have to register.
So I was wondering what methods are available for doing this?
#2
Posted 04 July 2009 - 12:12 PM
The target program/script has to check the HTTP referer variable passed as part of the page request. Depending on what it finds, the program branches to the appropriate code.
call ShowGoogleContent();
} else {
call ShowNotGoogleContent();
}
That's what it might look like in Perl; it would be similar in PHP and only slightly different in ASP.
As you can see, it's exceedingly simple. Unfortunately, it's also exceedingly unreliable. The HTTP referer variable is a completely voluntary one, and there's a growing number of browsers, security programs (ala Norton), and proxies that either hide the referer or outright lie about it. So long as Google is understanding and doesn't require 100 percent accuracy, it would probably be okay for this application. I sure wouldn't trust it with anything important, though.
#3
Posted 04 July 2009 - 12:16 PM
#4
Posted 04 July 2009 - 01:26 PM
Let's talk PHP instead of Perl, because PHP is an embedded scripting language and you've probably seen a lot of PHP pages. A very simple PHP page might work like this:
if ( eregi ( "www.google.com", $_SERVER['HTTP_REFERER'] ) ) {
echo '<html>';
echo '<head>';
echo ' <title>This is Google's Page</title>';
echo '</head>';
echo '<body>';
echo ' <h1>You only get to see this cause you came from Google</h1>';
echo '</body>';
echo '</html>';
} else {
echo '<html>';
echo '<head>';
echo ' <title>This is a Private Area</title>';
echo '</head>';
echo '<body>';
echo ' <h1>You have to pay me a thousand bucks to see this stuff!</h1>';
echo '</body>';
echo '</html>';
}
?>
That's highly inefficient, of course, but we're shooting for clarity not maintenance. Essentially, you just have to check the http_referer variable before you show anything to the visitor. Every programmer will likely do it a little differently, but that should give you gist.
#5
Posted 04 July 2009 - 03:02 PM
I wouldn't use google.com since traffic could be coming from other google properties. eg google.co.uk, google.com.au, etc.
I use the same sort of thing with that little rank extractor thing that records what the ranking position is in the various versions of Google. And I made it a little function, that gets a couple of variables plugged into it. This is php too.
function string_begins_with($string, $search)
{
return (strncmp($ref, $search, strlen($search)) == 0);
}
$search = "http://www.google.";
$ref = $_SERVER['HTTP_REFERER'];
if(string_begins_with($ref,$search) !=0) {
//Here put the content you want people to see if they came from Google
}else{
// Here put the normal You Need To Log in type of stuff
}
?>
As Ron already pointed out it's terribly unreliable for a lot of things if you absolutely need to have it fire correctly for everbody. But as long as Google understands and accepts that you cannot possibly account for every browser and firewall system out there you should be safe.
#6
Posted 24 November 2009 - 08:00 PM
I am thankful to find this posting, as I have been searching for days. The code posted above appears to be exactly the opposite of what I need, but I am hopeful someone can make it the reverse.
I have an iframed page, and often folks stumble on the iframed content on search engines but it is read out of context with the rest of my website. so, I am hoping for some PHP code I could insert into the iframed content that basically says.... if the referrer is NOT mywebsite.com, then click here to view this page in its proper form.
Any help is greatly appreciated, in advance!
Vlus
#7
Posted 25 November 2009 - 10:45 AM
You won't want to use PHP for your redirect. There are three issues with doing it via php.
1. Frames and iFrames are client side. PHP is server side.
2. You'd have to be very careful to keep a PHP redirect that fires from an iFrame page from throwing an error. The issue here being that php redirects should be sent before HTTP Headers have been sent to the browser, and the HTTP headers would have already been sent by the parent page before the PHP code could execute if the parent page was loaded normally.
3. Because PHP is server side code it would keep the search engine spiders from indexing your iFrame content if you didn't create an exception for them.
Long story short, it's a job better suited for Javascript. Which is also client side technology so is just a better fit.
The following would go in your iframe page(s). In practice the iframe should always be a child window, so the Javascript simply checks to see if it's being loaded as a parent window and redirects if this condition is met.
// Test to see if the page is being loaded in a frameset
if(top.locaiton == self.location) {
// If the test returns True, execute a Javascript redirect
// Put the main page address you want loaded here
top.location.href = '/mainpage.html';
}
</script>
Note: The top.location.href should be an absolute reference to the parent page url. So either /path/page.html all the way from the root of your web site or include the whole url address with the http on the front.
#8
Posted 25 November 2009 - 12:08 PM
do what ever
}
is nicer than having to call a string compare function
#9
Posted 25 November 2009 - 05:24 PM
For Jill's original question I'd do it via php, perl, asp or whatever server side code one feels most comfortable with.
For the iFrame I wouldn't use server side code. iFrames are client side. For any of several reasons a client side solution is going to be the best fit.
In both cases there are numerous ways one could do it. For vlus' question since the object of the exercise is to determine if someone loaded the iframe directly in their browser the easiest solution is to simply have the iframe to check to see if it's a parent or child window, then redirect of it's the parent.
#10
Posted 25 November 2009 - 06:10 PM
But was referring to Jill's OP and the referrer, how we use similar in the GRE, as i'm not very familiar with PHP, I just wondered what your PHP method vs Ron's was, is eregi a regex, where as you are using a built in text compare method.
#11
Posted 25 November 2009 - 06:16 PM
I haven't benchmarked it in awhile, but I doubt there is any appreciable server load difference between either method. There wasn't when I last checked.
#12
Posted 25 November 2009 - 08:03 PM
I am so grateful for your response to my post. I will try this code asap. I do apologize for interupting into this thread, however, I've been searching high and low for something to solve my dilemma, and this thread was about as logical a place as I could find where a knowlegeable answer might develop.
Thank you again,
vlus
#13
Posted 26 November 2009 - 05:08 AM
Randy -> Oh I thought there was some canny reason you were doing it your way, and you would enlighten me, guess not
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users







