In the header ( header.phtml ) I start the session :
<?php
if (session_status() == PHP_SESSION_NONE)
session_start();
?>
<!DOCTYPE html>
<html>
<head>
...
Now in other page I want to set a session value :
<script type="text/javascript">
$(document).ready(function() {
$("#add_reservS").on("click", function(e) {
<?php
$_SESSION['nb_ajout_client'] = 0;
?>
});
...
Then I increment this session value in other page :
public function ajouterExecAction($src = '', $pk_src = ''){
$client = new Client();
$client->ajouter($_POST);
if ($src == '')
$this->response->redirect('ReferentielClient');
else {
$_SESSION['nb_ajout_client']++;
...
}
...
}
Now inside another page I want to get this session value :
<script type="text/javascript">
$(document).ready(function() {
$("#btn_retour").on("click", function() {
var back = "<?php echo $previous; ?>";
if (back == "list_reserv")
window.history.back();
else {
var nb_back = "<?php echo $_SESSION['nb_ajout_client']; ?>";
alert("session nb ajout client = "+nb_back); // nb_back is blank !
}
});
});
</script>
The alert show a blank value ! So what is wrong in my approach ?