Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfset in html page

Contributor ,
May 27, 2012 May 27, 2012

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

4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 29, 2012 May 29, 2012

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"

...
Translate
LEGEND ,
May 27, 2012 May 27, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 27, 2012 May 27, 2012

Unfortunately, this is running on a shared server and the host has the Robust Exception permanently switched off.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2012 May 28, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 28, 2012 May 28, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2012 May 29, 2012

doug777 wrote:

... I don't know how to simulate a crawler in our local environment...

Easy: install HTTrack.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2012 May 29, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 27, 2012 May 27, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 27, 2012 May 27, 2012

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 28, 2012 May 28, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2012 May 28, 2012

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 28, 2012 May 28, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 28, 2012 May 28, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2012 May 29, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2012 May 29, 2012

Yes it works!!

That's fantastic. Many many thanks.

Doug

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2012 May 29, 2012
LATEST

!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2012 May 29, 2012

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">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 29, 2012 May 29, 2012

We are now certain there is no caching on the server.

Doug

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources