I have an html home page but wish to add some cf (CF9).
So I change the page name to index.cfm and add at line 1 :
<cfset arAcceptLanguage = GetPageContext().getRequest().getHeader("Accept-Language")>
This is later used by a javascript function.
It works fine and the browsers show everything correctly and all the javascript runs no problem.
But now some spiders cannot access the page. They get an error 500 and the error is
Error Occurred While Processing Request Variable ARACCEPTLANGUAGE is undefined.
The website is www.booxotel.com and the spider simulator I used is at
http://www.webconfs.com/search-engine-spider-simulator.php
Can anybody offer any clues how I can solve this?
Doug
doug777 wrote:
<cfset arAcceptLanguage = GetPageContext().getRequest().getHeader("Accept-Language")>
This is later used by a javascript function.
How do you pass the ColdFusion variable to Javascript? By means of the toScript function perhaps?
The ColdFusion variable belongs to the server, whereas Javascript variables belong to the client. It can easily happen that the user-agent(browser or robot) reloads the page, hence the Javascript, without contacting the server.
It is passed to javascript like this:
<cfoutput>
<cfif arAcceptLanguage EQ "">
<script language="JavaScript" type="text/javascript">
var countryCode = "us";
</script>
<cfelse>
<cfset arAcceptLanguage = arAcceptLanguage.Split(",")>
<script language="JavaScript" type="text/javascript">
var countryCode = "#LCase(Mid(arAcceptLanguage[1]&"-"&Left(arAcceptLanguage[1], 2), 4, 2))#";
</script>
</cfif>
</cfoutput>
Sorry the code I posted is not the correct code - it should be:
<cfoutput>
<cfif arAcceptLanguage EQ "">
<script language="JavaScript" type="text/javascript">
var countryCode = "us";
</script>
<cfelse>
<script language="JavaScript" type="text/javascript">
var countryCode = "#LCase(Mid(arAcceptLanguage, 4, 2))#";
</script>
</cfif>
</cfoutput>
This code is what is actually on the server. As I said before, it works correctly, but causes the 500 error and it looks as though the error occurs not at the cfset line or at the cfif line, but at line 8 in this snippet.
doug777 wrote:
Sorry the code I posted is not the correct code - it should be:
<cfoutput>
<cfif arAcceptLanguage EQ "">
<script language="JavaScript" type="text/javascript">
var countryCode = "us";
</script>
<cfelse>
<script language="JavaScript" type="text/javascript">
var countryCode = "#LCase(Mid(arAcceptLanguage, 4, 2))#";
</script>
</cfif>
</cfoutput>
The original error message was probably justified. Your Javascript indeed has no variable called arAcceptLanguage. What about something like this:
<cfset arAcceptLanguage=GetPageContext().getRequest().getheader("Accept-Lang uage")>
<cfset countryCode = lCase(mid(arAcceptLanguage, 4, 2))>
<cfoutput>
<cfif arAcceptLanguage EQ "">
<script language="JavaScript" type="text/javascript">
var countryCode = "us";
</script>
<cfelse>
<script language="JavaScript" type="text/javascript">
/* Define Javascript variables based on ColdFusion variables*/
var #toScript(countryCode, "countryCode")#;
var #toScript(arAcceptLanguage, "arAcceptLanguage")#;
</script>
</cfif>
</cfoutput>
doug777 wrote:
... I don't know how to simulate a crawler in our local environment...
Easy: install HTTrack.
doug777 wrote:
I have changed to your code and also changed the arAcceptLanguage variable to accLang (we thought there might be a caching problem), but the result is unchanged.
Then rule out caching. For example, place the following code at the top of the page, and see what happens.
<cfheader name="Cache-Control" value="no-cache,no-store,must-revalidate">
<cfheader name="Pragma" value="no-cache">
<cfheader name="Expires" value="-1">
I've had a look at HTTrack, but this just seems to download the website to view in a browser.
But we've already got the website and there is no CF error if you access these pages from a browser.
I can see that from the exception log both in our own local server and the log supplied by our online server host that the exceptions only occur when the site is accessed by some spiders.
To be any use I would need to be able to download and run a spider directly on our local host.
Doug
doug777 wrote:
I'm wondering if this is a timing problem. Is it possible that the response from the jvm to getRequest().getHeader("Accept-Language") is quick enough for a browser, which resolves the page later, but too slow for a crawler, which requires immediate resolution?
I think, when it goes wrong, the variable is simply not defined. What about testing with something like this:
<cfset arAcceptLanguage=GetPageContext().getRequest().getheader("Accept-Lang uage")>
<cfparam name="arAcceptLanguage" default="en-US,nl-NL;q=0.5">
Updated by BKBK
North America
Europe, Middle East and Africa
Asia Pacific