Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



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!



Photo
- - - - -

Methods For Showing Specific Content Based On Referrer


  • Please log in to reply
12 replies to this topic

#1 Jill

Jill

    Recovering SEO

  • Admin
  • 32,940 posts

Posted 04 July 2009 - 11:35 AM

I'm wondering if our tech-heads can explain what the different methods for showing specific content based on referrer might be.

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 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 966 posts
  • Location:Michigan USA

Posted 04 July 2009 - 12:12 PM

If there's more than one method, Jill, I'm unaware of it.

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.

CODE
if ($ENV{HTTP_REFERER}=~m/http:\/\/(www\.)?$google.com\//) {
    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 Jill

Jill

    Recovering SEO

  • Admin
  • 32,940 posts

Posted 04 July 2009 - 12:16 PM

So this might be a stupid question, but that code would go where?

#4 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 966 posts
  • Location:Michigan USA

Posted 04 July 2009 - 01:26 PM

It's not a stupid question at all, Jill, but it IS a complicated one. smile.gif

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:

CODE
<?php
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 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 04 July 2009 - 03:02 PM

One thing...

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.

CODE
<?php
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 vlus

vlus

    HR 1

  • Members
  • Pip
  • 2 posts

Posted 24 November 2009 - 08:00 PM

Hello,

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 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 25 November 2009 - 10:45 AM

Welcome vlus ! hi.gif

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.

CODE
<script type="text/javascript">

// 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 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,167 posts
  • Location:Worthing - England

Posted 25 November 2009 - 12:08 PM

Yup, it is very similar Randy, though I do prefer the perl syntax, makes code much smaller and is great for separating server processing and client output.

CODE
if($ref =~ /http:\/\/(www\.)?google\./i){
   do what ever
}


is nicer than having to call a string compare function smile.gif Though could you not use the method Ron has shown ?
CODE
eregi ( "www.google.", $_SERVER['HTTP_REFERER']
or simliar.

#9 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 25 November 2009 - 05:24 PM

We've got two very different questions going in the same thread 1dmf. So I'm not sure which one you're talking about.

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 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,167 posts
  • Location:Worthing - England

Posted 25 November 2009 - 06:10 PM

Yes sorry, I didn't mean to detract from your answer to vlus. I've seen your solution used for the term 'break out of frames', to ensure no-one loads your page as a child/frame.

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 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 25 November 2009 - 06:16 PM

Either or works fine.

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 vlus

vlus

    HR 1

  • Members
  • Pip
  • 2 posts

Posted 25 November 2009 - 08:03 PM

Randy,

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 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,167 posts
  • Location:Worthing - England

Posted 26 November 2009 - 05:08 AM

It's fine vlus, if you found this thread usefull and it's solved your problem, then HRF considers that 'mission accomplished'.

Randy -> Oh I thought there was some canny reason you were doing it your way, and you would enlighten me, guess not lol.gif




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

SPAM FREE FORUM!
 
If you are just registering to spam,
don't bother. You will be wasting your
time as your spam will never see the
light of day!