title: jQuery and ajax to set session variable in PHP
body: <p>I'm using a session variable in PHP to manage the current language in a multi-language site. To achieve what I want I'm using a flag icon that when clicked (jQuery) it tells lang_json.php to switch the session variable to the new language. </p>
  
  <p>I'm not getting errors on the jQuery side:</p>
  
  <pre><code>var sendData =  'en';  
  
  $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "lang_json.php",
      data: ({newLang: sendData}), 
      dataType: "json",
      success: function (msg) {
        alert('Success');
      },
      error: function (err){
        alert('Error');
      }
  });
  </code></pre>
  
  <p>But the PHP file is not setting the session variable:</p>
  
  <p>lang_json.php:</p>
  
  <pre><code>&lt;?php
  
  // Session variables
  session_name('aklogin'); // Starting the session
  session_start();
  
  if( isset($_POST['newLang']) ){
      $_SESSION['current_lan'] = $_POST['newLang'];
  }else{
      $_SESSION['current_lan'] = "Not Posting";
  }
  
  ?&gt;
  </code></pre>
  
  <p>The session variable is returning "Not Posting".</p>