views:

60

answers:

2

Hello I have a multi-langauage web. I set 3 links, Français... (href=changeLanguage.php?lang=fr,es,en)

changLanguage.php

session_start();

if(isset($_SESSION['bckTo']) && isset($_GET['lang'])){

    $lang = preg_replace('/[^a-z]/','',trim($_GET['lang']));

    #TODO
    #More vlidation ...

    $full_url = $_SESSION['bckTo']; 
    $full_url = str_replace(array('&lang=en','&lang=es','&lang=fr'),'',$full_url);

header('Location: '.$full_url.'&lang='.$lang.'');
}

$_SESSION['bckTo'] save the current URL for example: mysite.com/index.php?id=x&n_d=y The problem is, the header translate the URL to: mysite.com/index.php?id=x&n_d=y&lang=en.

Any idea will be appreciate

+4  A: 
Brad F Jacobs
Thanks for your answer, here how i proceed, I define the language variables ( define('INDEX_TITLE','Welcome ....'); ), and i have a script which checks for the get variable and include the proper translation file. (en, lang.en.php)...
jartaud
With the caveat that then each language version of a page would exist under the same URL. Serving different content under the same URL is bad for SEO, since either the alternate language versions are never indexed, or it's up to luck which version gets indexed. The URL *should* contain the language if it's a publicly accessible resource. For something like member-only pages it doesn't matter that much.
deceze
Thanks buddy, it's a good point, but if we care about SEO and we need a multilanguage site is there anything we can do?
jartaud
@jartaud Yes, give each site its own URL: `/en/page`, `/fr/page`, `/page?lang=en`, `/page?lang=fr`, `example.com/page`, `example.fr/page`… anything you like.
deceze
@deceze I dont i understand since the pages are created dynamically.
jartaud
@jartaud That doesn't have much to do with it. End users and search engines don't know or care *how* pages are created, only at which URL they are. The URL schema doesn't prescribe *how* pages are generated, or not generated. Try googling for "pretty URLs" as a start.
deceze
+1  A: 

Running html_entity_decode will convert those HTML entities back into ampersands.

http://us2.php.net/manual/en/function.html-entity-decode.php

erjiang
Thanks for you answer. It does the job.
jartaud