To solve this, create a page called index.php
, within it, you will have language options, only flags of each country for example.
You will then have a choice, which depending on the choice you will be redirected to the same page but with different parameter, could be used this code in index.php
for example:
<a href=pagina_inicial.php?lang=pt_PT >Português</a>
<a href=pagina_inicial.php?lang=en_US >Inglês</a>
And then inside your "bd-connected file" from which you posted the code in your question, it would work as follows:
$lang = $_GET['lang'];
if ($lang == "pt_PT")
$conn->exec("SET lc_time_names = 'pt_PT'");
else
$conn->exec("SET lc_time_names = 'en_US'");
You must be wondering "'Cause I didn’t just do it this way?:"
$lang = $_GET['lang'];
$conn->exec("SET lc_time_names = '".$lang."'");
Because it would become an extremely vulnerable target to attacks via SQL Injection, so I’d be very insecure(never use variables that can be sent by the user within SQL code)
This way I told you, you can know which language the user wants, at the time of execution of your command, via a parameter that it sent when choosing which language on the page index.php
.
It’s not enough to make a
if
to change thept_PT
foren_US
?– Felipe Avelar
@Felipeavelar I could do that, but this line is from the file that makes the connection to the bd. And the include of it in the pages happens before picking up the language.
– marcelo2605