Results 1 to 6 of 6

Thread: modifying a URL

  1. #1
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default modifying a URL

    Hi everyone

    Im running a multi language site using typo3

    The url for the site in english is

    'www.url.com'

    In welsh, its:

    'www.url.com&L=3'

    is there a PHP script i can use that modifies the url, either adding or removing "&L=3" so that users can switch languages simply by click on a hyperlink?

    i would need to embed the PHP into the HTML template which is used by over 50 pages so i am unable to manually code hyperlinks for each page.

    many thanks

    Tom
    Last edited by Snookerman; 04-22-2009 at 09:04 AM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Like this:
    HTML Code:
    <a href="url.com?L=3">Welsh</a>
    And then in php at the top of the index page:

    PHP Code:
    <?php
    if($_GET['L'] == 3){
      echo 
    "Welsh";
    }
    ?>
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    SirTom909 (03-26-2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi,

    I think the most efficient way of doing this would be to save the user's preference as a session variable or store in a cookie.

    PHP Code:
    <?php

    if(isset($_SESSION['language'])){
    $language=$_SESSION['language'];
    // insert code the that loads the correct language
    }

    if(isset(
    $_POST['switch_language'])){
      
    $_SESSION['language']=$_POST['language'];
    }

    ?>

    <form>
    <fieldset>
    <legend>Switch Language</legend>
    <select name="language">
    <option>Choose</option>
    <option value="1">English</option>
    <option value="2">Spanish</option>
    <option value="3">Welsh</option>
    </select>
    <input type="submit" name="switch_language" value="Switch" />
    </fieldset>
    </form>

  5. The Following User Says Thank You to glambert For This Useful Post:

    SirTom909 (03-26-2009)

  6. #4
    Join Date
    Sep 2008
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Nile,Glambert - thank you both for your help.

    I tried Nile suggestion but it doesnt apply to every page

    going to give Glamberts suggestion a try this morning

    thanks again

    Tom

  7. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well, you'd have to change the html to:
    HTML Code:
    <a href="?L=3">Welsh</a>
    But glad to help!

    It seems your topic is solved... Please set the status to resolved.. To do this:
    Go to your first post ->
    Edit your first post ->
    Click "Go Advanced" ->
    Then in the drop down next to the title, select "RESOLVED"
    Jeremy | jfein.net

  8. #6
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default You can use the link in an include file

    If you have 'Includes' folder in your site directory, then probably you have some files that contain code which will get loaded in almost each and every page (all the pages which has called that include file using include() function)

    If you check those include files, then one of them might be an include file for page header, which will be the right place to add just a html link to switch language.

    Usually, all php sites have a folder to save these include files, to save typing.

    Anyway, your question is not limited to php, because all you need is to add just one link in each and every page, and you have various other options to do that.

    1) If you have a common navigation bar for all pages then you can add the link to switch language there. Usually many site designing programs have an option to create a navigation bar.

    2) Or you can modify an existing common link into this link by a tool called 'Search and replace'.. If you google this, you can find this simple free tool.

    3) You can simply rename your index page and add a new index page that links to the current index page. The new index page can have a short summary of your site and links to choose the language.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •