Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Random language for spiders


boxtel

Recommended Posts

Not sure if I mess up any ranking with this.

 

before I had my default language set to english. Now most spiders do not have a language setting (There ia a chinese one that does) so the pages they would get were always my default language.

 

That meant that all spiders would get my site and index it in english unless they followed the change language button.

 

That meant that all my chinese language pages would be index as:

 

http://www.crystallight.com.tw/product_inf...=23&language=tw

 

(always the language=tw at the end)

 

So I thought, why not provide randomly different languages to the spiders unless they request a specific one via a url like above.

 

so I placed this in my application top :

 

//force language settings for spiders if not requested

if($spider_flag) {

if (!isset($HTTP_GET_VARS['language'])) {

// no specific language requested, choose a random one so all languages get a chance to be indexed

$language_array[] = array('language' => 'english', 'id' => 1);

$language_array[] = array('language' => 'tchinese', 'id' => 6);

 

$rl = rand(0,sizeof($language_array)-1);

$language = $language_array[$rl]['language'];

$languages_id = $language_array[$rl]['id'];

}

}

 

 

Let's see what the results will be.

Treasurer MFC

Link to comment
Share on other sites

  • 1 year later...

Hi Amanda,

While reading posts in forum A Store Speed Optimization in Progress, Step by step from a vanilla install! I came across one of your postings. Post #315

That is because you do not set your language or currency when a spider visits, DO SO!

in application_top BEFORE this code :

// include the language translations

require(DIR_WS_LANGUAGES . $language . '.php');

 

 

you add this code (adjust to your language/currency preferences) :

 

$browser_language = getenv('HTTP_ACCEPT_LANGUAGE'); # Is this obtained from the user agent?

$given_language = $_GET['language']; # this would be some value for variable language that we wold pass in the URL? How is language initialized?

 

// Setting the language and currency for spiders only

if ($spider_flag) {

//force language settings for spiders if not requested

if ($given_language == '') { // language not specifically requested

if ($browser_language != '') { // spider with language setting, yes they exist

$lng->get_browser_language(); If spider has language set then you save those values to class $lng->?

$language = $lng->language['directory']; Does the language directory have the languages you use?

$languages_id = $lng->language['id']; Once you know the language you set the language ID?

} else {

// no specific language requested, choose a random one so all languages get a chance to be indexed

$language_array[] = array('language' => 'english', 'id' => 1);

$language_array[] = array('language' => 'tchinese', 'id' => 6);

$rl = rand(0,1);

$language = $language_array[$rl]['language'];

$languages_id = $language_array[$rl]['id'];

 

// override if useragent indicates location like yahoo china

if (stristr($user_agent, 'china')) { How do you override the useragent?

$language = 'tchinese';

$languages_id = 6;

}

}

}

 

// spider currency

if ($language == 'tchinese') { Once you know the language then your able to set the shop currency, so if you detect that a browser has English you show all your sites currencies in USD and it you detect that a browsers language is tchinesse then currency is TWD?

$currency = 'TWD';

} else {

$currency = 'USD';

}

}

and all spiders will happily generate page cache files for you and your "real" clients, free and gratis.

 

PS. ALWAYS make sure that spiders do get the same content as "real" customers so don't use statements like:

if (!spider_flag) {
 echo content for real customers only;
 }

The above code looks to be related to the tip you are giving here. I would like to implement what your are suggesting. I have a few questions hope you can assist me with.

 

If I read the code line by line see if I understand the process. Comments in bold by your code.

 

 

  • In the code above there are a few places were you call this $lng-> , Class? and some of its function members? get_browser_language(), language['directory'], $lng->language['id'], is this a class that you created and just pulling the data off the functions?
  • I also have page_cache implemented, Do I need to do any other code modification to the other pages in conjunction with the code above?
  • How does the spider get told what language it should be, currently I only have English but plan to have a few more POL, TW.
  • I also see that you tell the spider the currency, how does the spider get set with the currency value?
  • I want to take advantage from your suggestions to have the spider do some of the work of caching some of the pages.
  • I would appreciate it very much to see how you implemented this on your site.

Regards, Marizka. As always Thank You, I very much appreciate your time and help.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...