title: Setting PHP session variables with ajax
body: <p>Want to change value of SESSION variable "fullname" without refreshing the page.</p>
  
  <p>My implementation using ajax:</p>
  
  <p>Page 1 html:</p>
  
  <pre><code>&lt;input type="text" name="fullname" id="fullname" placeholder="Full name"&gt;
  
  &lt;button onclick="setSession()"&gt; GO &lt;/button&gt;
  </code></pre>
  
  <p>Page 1 script:</p>
  
  <pre><code>&lt;script&gt;
  function setSession(){
     var fullname = $("#fullname").val();
     var dataString = 'fullname=' + fullname;
  
     $.ajax({
          type: "POST",
          url: "Page2.php",
          data: dataString,
          cache: false,
          success: function( data ) {
               if(data === 'True'){
                   alert("&lt;?php echo $_SESSION['fullname'];?&gt;");
                }
              }
          });
        }
  &lt;/script&gt;
  </code></pre>
  
  <p>And in Page 2:</p>
  
  <pre><code>session_start();
  $_SESSION["fullname"] = $_POST["fullname"];
  echo 'True';
  exit();
  </code></pre>
  
  <p>It doesn't change the value of the session variable.</p>
  
  <p>Both pages have session_start().</p>