0

My site is structured in the following way:

index.php

  • fileA.php
  • fileB.php
  • fileC.php
  • ecc.

Each of this files have associated 3 language files (english, german and italian), stored in a folder. The languages are changing dynamically with an select menu:

<form name="switch_menu" id="lang" action="" method="post">
<select name="lingua" class="switch" onchange="this.form.submit()">
<option value="lang_it" <?php if($lang == "lang_it"){ echo "selected=\"selected\""; }?>>Italiano</option>
<option value="lang_de" <?php if($lang == "lang_de"){ echo "selected=\"selected\""; }?>>Deutsch</option>
<option value="lang_en" <?php if($lang == "lang_en"){ echo "selected=\"selected\""; }?>>English</option>
</select>
</form>

and the code in the files is this one:

switch($lang){
case 'lang_it': include_once('folder/it/fileA.it.php'); break;
case 'lang_de':  include_once('folder/de/fileA.de.php'); break;
case 'lang_en':  include_once('folder/en/fileA.en.php'); break;
default: include_once('folder/en/fileA.en.php'); break;
 }

where fileA.en.php,fileA.it.php and fileA.de.php are the language content.

Is it possibile to manipulate the second part of the code with some if statement or similar, so the selected language is shown in the url? Otherwise the search engines won't see the other languages (italian and german). Otherwise can i add some code to achieve the purpose?

Thanks in advance for any hints.

Someone33
  • 568
  • 2
  • 8
  • 25

1 Answers1

0

Why not just using GET instead of POST in the form? That will put the $lang variable in your URL, something like http://yourdomain.com/fileA.php?lang=it

Then, for the crawler to look at the different languages more efficiently, you could make internal links to the site using the URL with the lang GET variable.

Also, take a look at Gettext, it is a much better way to implement internationalization.

JuanXarg
  • 428
  • 2
  • 11
  • post is more secure than get...is it possibile to do it with $_POST? – Someone33 Feb 20 '14 at 19:23
  • By select list can be. – Lkopo Feb 20 '14 at 19:24
  • Well, I have to disagree there (and I'm [not the only one](http://stackoverflow.com/questions/198462/is-either-get-or-post-more-secure-than-the-other)). The only difference is that POST is not shown in the URL, but since in this case you WANT it to be shown, then there's not much more to say :) GET is exactly what you need in this case. – JuanXarg Feb 20 '14 at 19:28
  • @JuanXarg how to do rewrite the second part of the code in the best way? Never used gettext :-( – Someone33 Feb 20 '14 at 19:38
  • That's a big topic. [here](http://www.sitepoint.com/localizing-php-applications-1/)'s a guide that will walk you through it. It seems complicated at first, but it will save you many hours and headaches in the future. And I'm talking from experience! – JuanXarg Feb 20 '14 at 20:00