hi guys,
this is my first post 😉

i have the function:

<?php
   if( $_POST["name"]  ) {
      if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
         $_SESSION['TDM_LANG']='it';
         TDMRedirect($_SERVER['REQUEST_URI']);

  }
  else {$_SESSION['TDM_LANG']='en';
  TDMRedirect($_SERVER['REQUEST_URI']);
  }

  exit();
   }
?>
<html>
   <body>

  <form action = "<?php $_PHP_SELF ?>" method = "POST">
     Name: <input type = "text" name = "name" />

     <input type = "submit" />
  </form>

   </body>
</html>

but i need to correct it: with this function i change the module language with a form, if the input are numbers i get italian language, if the input are letters i get the english language. I need to modify the condition in a really simple way, cancel the input form and get this:

italianflag.jpg if i click on this so

{
$SESSION['TDM_LANG']='it';
TDMRedirect($
SERVER['REQUEST_URI']);

  }

englishflag.jpg if i click on this so:

{$SESSION['TDM_LANG']='en';
TDMRedirect($
SERVER['REQUEST_URI']);
}

what i need is to edit the condition of php and html, getting crazy with this stupid function... thanks in advance!!!
i took this example that is working on my site but is not suitable to my needs, i simply need the same result when i click on links of two flags

    PHP_SELF is vulnerable to an XSS Attack. Remove the action completely.

      benanamen;11065317 wrote:

      PHP_SELF is vulnerable to an XSS Attack. Remove the action completely.

      ok, thanks for the info 🙂 could you suggest me the correct solution to make the function work with flags instead of a form?

        You can still use a form: one with just two <button>s. I'd use a GET, myself.

        Consider also, when you first show the page (and don't have any existing language preference), looking in the request for an "Accept-Language:" header, and basing its initial value on that.

          Weedpacket;11065325 wrote:

          You can still use a form: one with just two <button>s. I'd use a GET, myself.

          Consider also, when you first show the page (and don't have any existing language preference), looking in the request for an "Accept-Language:" header, and basing its initial value on that.

          thanks for the suggestion, coud you make me an example with the code that i posted?

            Edit, i modified the code in this way and it's working:

            <?php
            if(isset($POST['button1'])) {
            $
            SESSION['TDM_LANG']='it';
            TDMRedirect($_SERVER['REQUEST_URI']);

              }
            
              if(isset($_POST['button2'])) {
                 $_SESSION['TDM_LANG']='en';
            	 TDMRedirect($_SERVER['REQUEST_URI']);
            
              }

            ?>
            <html>
            <body>

              <form  method = "POST" action=''>
            
            
                 <input type="submit" name="button1"  value="italian">
            	 <input type="submit" name="button2"  value="English">
            
              </form>

            </body>
            </html>

            do you know how to set the default language with "Accept-Language:" ??
            any code integration will be really appreciated!

              i gave a look at the links and i just need your confirmation regarding this way to set the session language:

              $SESSION['TDM_LANG'] = substr($SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);

              in this way i think that i'm setting the language according to the visitor preferences, but is there a simple way to set the DEFAULT LANGUAGE always italian ?

                Maybe something like this?

                $_SESSION['TDM_LANG'] = 'italian';
                if(!empty(_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                    $_SESSION['TDM_LANG'] = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
                }
                
                  NogDog;11065359 wrote:

                  Maybe something like this?

                  $_SESSION['TDM_LANG'] = 'italian';
                  if(!empty(_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                      $_SESSION['TDM_LANG'] = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
                  }
                  

                  tried it but there is some errrors, blank page...

                    There's a real $imple $yntax error in there ... look closely. And don't yell @ for a $imple typo ... let the rest of us do that instead!

                      dalecosp;11065371 wrote:

                      There's a real $imple $yntax error in there ... look closely. And don't yell @ for a $imple typo ... let the rest of us do that instead!

                      Thanks, i corrected the SERVER error in $SERVER but if i add that code i have the following situation:

                      first loaded page in italian, any link after that is automatically switch the session in english so i have to select manually italian for any link

                        So...I think maybe what you are after is setting it only if not already set?

                        if(empty($_SESSION['TDM_Language'])) {
                          $_SESSION['TDM_LANG'] = 'italian';
                          if(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                            $_SESSION['TDM_LANG'] = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
                          }  
                        }

                        Then if is set elsewhere, such as by the code that handles the click of a language flag, it won't try to reset it as long as the session is active.

                          NogDog;11065387 wrote:

                          So...I think maybe what you are after is setting it only if not already set?

                          if(empty($_SESSION['TDM_Language'])) {
                            $_SESSION['TDM_LANG'] = 'italian';
                            if(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                              $_SESSION['TDM_LANG'] = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
                            }  
                          }

                          Then if is set elsewhere, such as by the code that handles the click of a language flag, it won't try to reset it as long as the session is active.

                          what i need is: set ITALIAN language as default language if is not already setted a second language

                          should the function return this?

                            Well, I used the wrong array key in the first line, but the intention was:

                            • If the "TDM_LANG" session value already exists, use that. (Presumably the user already selected explicitly or via HTTP header.)

                            • If not, but the browser sent an "Accept-Language" HTTP header, use that.

                            • Otherwise, set it to "italian"

                              NogDog;11065397 wrote:

                              Well, I used the wrong array key in the first line, but the intention was:

                              • If the "TDM_LANG" session value already exists, use that. (Presumably the user already selected explicitly or via HTTP header.)

                              • If not, but the browser sent an "Accept-Language" HTTP header, use that.

                              • Otherwise, set it to "italian"

                              perfect,
                              many many thanks for the help and explanation

                                Write a Reply...