| Important Announcement: ***Need an Affordable SEO Website Review?*** |
![]() ![]() |
Jul 4 2009, 11:35 AM
Post
#1
|
|
![]() High Rankings Advisor Group: Admin Posts: 29,201 Joined: 21-July 03 User's local time: Feb 9 2010, 03:28 PM From: Ashland, MA Member No.: 2 |
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? |
|
|
|
Jul 4 2009, 12:12 PM
Post
#2
|
|
![]() HR 6 Group: Moderator Posts: 918 Joined: 24-July 03 User's local time: Feb 9 2010, 03:28 PM From: Michigan USA Member No.: 17 |
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. |
|
|
|
Jul 4 2009, 12:16 PM
Post
#3
|
|
![]() High Rankings Advisor Group: Admin Posts: 29,201 Joined: 21-July 03 User's local time: Feb 9 2010, 03:28 PM From: Ashland, MA Member No.: 2 |
So this might be a stupid question, but that code would go where?
|
|
|
|
Jul 4 2009, 01:26 PM
Post
#4
|
|
![]() HR 6 Group: Moderator Posts: 918 Joined: 24-July 03 User's local time: Feb 9 2010, 03:28 PM From: Michigan USA Member No.: 17 |
It's not a stupid question at all, Jill, but it IS a complicated one. (IMG:style_emoticons/default/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. |
|
|
|
Jul 4 2009, 03:02 PM
Post
#5
|
|
![]() Convert Me! Group: Admin Posts: 17,380 Joined: 17-August 03 User's local time: Feb 9 2010, 02:28 PM Member No.: 551 |
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. |
|
|
|
Nov 24 2009, 08:00 PM
Post
#6
|
|
|
HR 1 ![]() Group: Members Posts: 2 Joined: 24-November 09 User's local time: Feb 9 2010, 03:28 PM Member No.: 27,351 |
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 |
|
|
|
Nov 25 2009, 10:45 AM
Post
#7
|
|
![]() Convert Me! Group: Admin Posts: 17,380 Joined: 17-August 03 User's local time: Feb 9 2010, 02:28 PM Member No.: 551 |
Welcome vlus ! (IMG:style_emoticons/default/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. |
|
|
|
Nov 25 2009, 12:08 PM
Post
#8
|
|
![]() Keep Asking, Keep Questioning, Keep Learning ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Active Members Posts: 1,950 Joined: 24-May 07 User's local time: Feb 9 2010, 08:28 PM From: Worthing - England Member No.: 17,339 |
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 (IMG:style_emoticons/default/smile.gif) Though could you not use the method Ron has shown ? CODE eregi ( "www.google.", $_SERVER['HTTP_REFERER'] or simliar.
|
|
|
|
Nov 25 2009, 05:24 PM
Post
#9
|
|
![]() Convert Me! Group: Admin Posts: 17,380 Joined: 17-August 03 User's local time: Feb 9 2010, 02:28 PM Member No.: 551 |
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. |
|
|
|
Nov 25 2009, 06:10 PM
Post
#10
|
|
![]() Keep Asking, Keep Questioning, Keep Learning ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Active Members Posts: 1,950 Joined: 24-May 07 User's local time: Feb 9 2010, 08:28 PM From: Worthing - England Member No.: 17,339 |
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. |
|
|
|
Nov 25 2009, 06:16 PM
Post
#11
|
|
![]() Convert Me! Group: Admin Posts: 17,380 Joined: 17-August 03 User's local time: Feb 9 2010, 02:28 PM Member No.: 551 |
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. |
|
|
|
Nov 25 2009, 08:03 PM
Post
#12
|
|
|
HR 1 ![]() Group: Members Posts: 2 Joined: 24-November 09 User's local time: Feb 9 2010, 03:28 PM Member No.: 27,351 |
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 |
|
|
|
Nov 26 2009, 05:08 AM
Post
#13
|
|
![]() Keep Asking, Keep Questioning, Keep Learning ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Active Members Posts: 1,950 Joined: 24-May 07 User's local time: Feb 9 2010, 08:28 PM From: Worthing - England Member No.: 17,339 |
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 (IMG:style_emoticons/default/lol.gif) |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 9th February 2010 - 03:28 PM |