Problems in PHP code

Discussion in 'PHP' started by JK Net, Oct 21, 2008.

  1. #1
    Good friends,

    I am with the following prob ...


    Files concerned:

    INDEX.PHP

    <?php
    session_start();
    if ($_SESSION['idioma']){
    $Idioma = $_SESSION['idioma'];
    include("$Idioma.php");
    }
    else {
    include("portugues.php");
    }
    ?>
    
    
    <p><a href="mudaidioma.php?idioma=portugues"><img src="/layout/pt.png" width="16" height="11" border="0" /></a>
    <a href="mudaidioma.php?idioma=ingles"><img src="/layout/gb.png" width="16" height="11" border="0" /></a></p>
    
    <?php
    echo "$Texto1<br />";
    echo "$Texto2<br />";
    echo "$Texto3<br />";
    ?>
    
    Code (markup):


    MUDAIDIOMA.PHP

    <?php
    session_start();
    $Idioma = $_GET["idioma"];
    $_SESSION['idioma'] = $Idioma;
    header("Location: index.php");
    ?>
    Code (markup):


    PORTUGUES.PHP

    <?php
    $Texto1 = "Teste de texto";
    $Texto2 = "Este texto &eacute; um teste";
    $Texto3 = "Teste de idiomas ok!";
    ?>
    Code (markup):

    INGLES.PHP

    <?php
    $Texto1 = "Text test";
    $Texto2 = "This text is a test";
    $Texto3 = "Language test ok!";
    ?>
    Code (markup):


    ---

    As you can see the idea is to create a session for exchange of language ... the issue is that there is a flaw in this code, and I am not able to understand ... it is not working.

    Somebody help me?


    Thanks!!!
     
    JK Net, Oct 21, 2008 IP
  2. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    session_start();
    if ($_SESSION['idioma'] == 'ingles'){
      include("ingles.php");
    } else {
      include("portugues.php");
    }
    ?>
    PHP:
    could work, please try.

    Also dont ever use include("$any_unescaped_variable_from_GET_POST_REQUEST_or_SESSION.php") - this poses a security risk.
     
    keyaa, Oct 21, 2008 IP
  3. srikanthever4u

    srikanthever4u Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Hi it is working iam test

    of u want multiple language use smarty
    that one really help u
     
    srikanthever4u, Oct 21, 2008 IP
  4. srikanthever4u

    srikanthever4u Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    hi dont use sessions because
    some problems are occurs
     
    srikanthever4u, Oct 21, 2008 IP
  5. JK Net

    JK Net Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks!!! ;)
     
    JK Net, Oct 21, 2008 IP
  6. JK Net

    JK Net Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6

    This only gives to 2 languages ... I like to have 3 or more?
     
    JK Net, Oct 21, 2008 IP
  7. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <?php
    session_start();
    switch($_SESSION['idioma']) {
    case "ingles":
    include("ingles.php");
    break;
    case "whatever":
    include("ingles1.php");
    break;
    case "whatever2":
    include("ingles2.php");
    break;
    default:
    include("portugues.php");
    break;
    }
    ?>
     
    Kyosys, Oct 21, 2008 IP
  8. JK Net

    JK Net Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks...

    I was doing well ... missing me was the "default"
     
    JK Net, Oct 21, 2008 IP