Jump to content

URL Problem


anilm

Recommended Posts

Hi

1.

I have a website , and at the top of the page, there is a dropdown list to let the users specify either English and Spanish as a language.

 

This works fine if the language is the first selection made on the webpage, and the URL changes to http://www.mywebsite.es/index.php?lang=es if Spanish..as it should.

 

However, if I perform a search further down  the page using either free text entry, or by any of the other dropdown boxes, then the language part of the URL is not recognized.

 

So, instead of a search result ending up as 

 

http://www.mywebsite.es/index.php?lang=es/search.php?location=&type1=&price1=&condition=&category=&q=shoes

I get

http://www.cocoba.es/search.php?location=&type1=&price1=&condition=&category=&q=shoes

 

Here are snippets of the script I have at the moment:

 

<script type="text/javascript">
function go(){
location=document.lan.langu.
options[document.lan.langu.selectedIndex].value
}
</script>
 
          <form name="lan">
          <select name="langu" size="1" onChange="go()">
              <option><?php print translate("Language"); ?></option>
              <option value="">English</option>
              <option value="/index.php?lang=es">Español</option>
          </select>
          </form>
 
    <form name='search' action='<?php print $config_baseHREF ?>search.php'>
   (the search.php files calls up the rest of the URL after the language).
 
2.
Also, if the language is changed half way through a session, is there a way to change the language of the page, so that the existing content on the webpage remains, and does not go back to the home page.
 
Thanks
 
 
 
 

 

 

Link to comment
Share on other sites

 

Hi

1.

I have a website , and at the top of the page, there is a dropdown list to let the users specify either English and Spanish as a language.

 

This works fine if the language is the first selection made on the webpage, and the URL changes to http://www.mywebsite.es/index.php?lang=es if Spanish..as it should.

 

However, if I perform a search further down  the page using either free text entry, or by any of the other dropdown boxes, then the language part of the URL is not recognized.

 

So, instead of a search result ending up as 

 

http://www.mywebsite.es/index.php?lang=es/search.php?location=&type1=&price1=&condition=&category=&q=shoes

I get

http://www.cocoba.es/search.php?location=&type1=&price1=&condition=&category=&q=shoes

 

Here are snippets of the script I have at the moment:

 

<script type="text/javascript">
function go(){
location=document.lan.langu.
options[document.lan.langu.selectedIndex].value
}
</script>
 
          <form name="lan">
          <select name="langu" size="1" onChange="go()">
              <option><?php print translate("Language"); ?></option>
              <option value="">English</option>
              <option value="/index.php?lang=es">Español</option>
          </select>
          </form>
 
    <form name='search' action='<?php print $config_baseHREF ?>search.php'>
   (the search.php files calls up the rest of the URL after the language).
 
2.
Also, if the language is changed half way through a session, is there a way to change the language of the page, so that the existing content on the webpage remains, and does not go back to the home page.
 
Thanks

 

Sorry, but the 2 urls above should be:

mywebsite.es/index.php?lang=es/search.php?location=&type1=&price1=&condition=&category=&q=shoes

and

mywebsite.es/search.php?location=&type1=&price1=&condition=&category=&q=shoes
Link to comment
Share on other sites

You're missing a bit of code here that describes what handles the ?lang=es portion, but if I were to guess, the translate() function does that?

 

If so, I think you would be better off storing the language selection within a session variable, and using that within the translate, rather than the URL.

$allowable_langs = array('en', 'es');
if (isset($_GET['lang']) && in_array($_GET['lang'], $allowable_langs)) {
    $_SESSION['lang'] = $_GET['lang'];
}

Within the translate function, just access the wanted variable by using

$_SESSION['lang'];
Edited by iarp
Link to comment
Share on other sites

  • 2 weeks later...

Hello. Sorry for the delay getting back about this. I am quite new to programming, so was wondering if you could explain your previous post:

 

At the moment, I now have the following:

 

<script type="text/javascript">
function go(){
location=document.langu.
options[document.langu.selectedIndex].value.search.php
}
</script>
 
<form name='search' action='<?php print $config_baseHREF ?>search.php'>
<select class="form-control" name="langu" size="1" onChange="go()">
<option value='es'>Espanyol</option>
<option <?php print ((isset($_GET["langu"]) && ($_GET["langu"]=="es"))?"selected='selected'":""); ?> value='en'>English</option>
</select>
</form>
 
and another file which has:
 
<?php
switch($_SERVER["REQUEST_URI"])
  {
  case "/search.php?langu=en": // Spanish
  $translate["Idioma"] = "Language";
  $translate["Nuevo"] = "New";
  $translate["Usado"] = "Used";.....etc
  break;
  }
  function translate($text)
  {
    global $translate;
    return (isset($translate[$text])?$translate[$text]:$text);
  }
?>
 
Sorry to ask such a basic question, but could you tell me how I should incorporate your previous suggestion.
Thanks
 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.