Copy link to clipboard
Copied
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:
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-Language")>
<cfparam name="arAcceptLanguage"
...Copy link to clipboard
Copied
Well the error message itself pretty much tells you the first thing to do to start troubleshooting this:
Variable ARACCEPTLANGUAGE is undefined. Resources: Enable Robust Exception Information to provide greater detail about the source of errors.
That's what you should be doing.
--
Adam
Copy link to clipboard
Copied
Unfortunately, this is running on a shared server and the host has the Robust Exception permanently switched off.
Copy link to clipboard
Copied
Unfortunately, this is running on a shared server and the host has the Robust Exception permanently switched off.
Do you not have a dev environment that is under your control?
You should be able to emulate whatever that spider-test-site thing does, and replicate this on dev.
--
Adam
Copy link to clipboard
Copied
Do you not have a dev environment that is under your control?
Yes, but there is no error from a browser on our dev server, and I don't know how to simulate a crawler in our local environment, and I don't think this server has a fixed IP so that it can be accessed from the web.
Doug
Copy link to clipboard
Copied
doug777 wrote:
... I don't know how to simulate a crawler in our local environment...
Easy: install HTTrack.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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-Language")>
<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>
Copy link to clipboard
Copied
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.
Doug
Copy link to clipboard
Copied
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?
Doug
Copy link to clipboard
Copied
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-Language")>
<cfparam name="arAcceptLanguage" default="en-US,nl-NL;q=0.5">
Updated by BKBK
Copy link to clipboard
Copied
Yes it works!!
That's fantastic. Many many thanks.
Doug
Copy link to clipboard
Copied
!
Copy link to clipboard
Copied
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">
Copy link to clipboard
Copied
We are now certain there is no caching on the server.
Doug
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more