I'm starting with PHP, so I have no idea what's going wrong. I'm trying to update some value in my $_SESSION var using a function, but is not working. First of all, I started the session and set a default value to the session if it is "undefined" in my header.php:
<?php
session_start();
if (!isset($_SESSION["locale"])) {
$_SESSION["locale"] = 'pt_BR';
}
?>
Then I have some ajax which calls my PHP function.
$('#change_locale_br').click(function() {
$.ajax({
type: "POST",
url: "i18n/i18n_functions.php",
data: { action: "changelocale", new_locale: "pt_BR" },
success: function() {
}
});
});
After in the php file, I have the following code:
<?php
function changelocale($l) {
$_SESSION["locale"] = $l;
}
if(isset($_POST['action']) && $_POST['action'] == 'changelocale'){
$l = $_POST['new_locale'];
changelocale($l);
}
?>
So the changelocale function is being called with the different values (pt_BR, es and etc), but after called it doesn't really change the $_SESSION["locale"] value.
I made a lot of research and NONE of the suggestions made here or in the PHP documentation page worked. Does someone knows what could be done in this case?
Thanks in advance.