title: Passing a $_SESSION failed when creating the $_SESSION within Ajax function
body: <p>I have a simple registration form and the new comers will be registered with an ajax function. There I create a <code>$_SESSION['is_logged']</code> when the registration is finished.
  On var_dumb I get that the var is set. But when redirect on another page it is empty (I have included already the session_start() on the both pages...
  I have read somewhere in the net that:</p>
  
  <blockquote>
    <p>"Sessions are ONLY written on a page load/refresh".</p>
  </blockquote>
  
  <p>Is this the case, or I have to look for some other issues within my code.</p>
  
  <p>the ajax:</p>
  
  <pre><code>        $.ajax({
          url:"../controllers/register.php",
          type:"POST",
          data:res,
          success: function(responce){
              if (responce==1) {
                  $('#msg').addClass('msg-warning');
                  $("#form").css('display',"none");
                  $('#msg').append("&lt;p&gt;It seems that you have already submited the form. Click to "+
                      " &lt;a href='login.php'&gt;log-in&lt;/a&gt; or to &lt;a href='register.php'&gt;register&lt;/a&gt;.&lt;/p&gt;");
              }
              else if (responce==2) {
                  $('#msg').addClass('msg-warning');
                  $("#form").css('display',"none");
                  $('#msg').append("&lt;p&gt;You have successfully created account. Click to "+
                      " &lt;a href='start.php'&gt;welcome&lt;/a&gt; to start your .&lt;/p&gt;");
                  $('.menu').append("&lt;li&gt;&lt;a href='logout.php'&gt;Log out&lt;/a&gt;&lt;/li&gt;")
              }
              else{
                  $('#msg').text(responce);
              }
  
          },
          error: function(){
              $('#msg').text("Opss, try again");
          }
      });
  </code></pre>
  
  <p>the register.php file:</p>
  
  <pre><code>    if (isset($_SESSION['submited'])) {
      echo 1;
      exit;
  }
  
  include_once('../models/functions.php');
  
  // Give the post parametters to another var
  $arr=$_POST;
  
  // function for uploading
  $reg = registerMe($arr);
  
  if ($reg === true) {
      $_SESSION['submited']=1;
      $_SESSION['is_logged']=1    
      echo(2);
  }   
  else{
      echo($reg); 
  }
  exit;
  </code></pre>
  
  <p>The <code>session_start();</code> is included in the header of the first page where from the ajax is started.And the second page - where the $_SESSION['is_logged'] is lost, again the <code>session_start()</code>; is part of <code>dc_header();</code> function. start.php:</p>
  
  <pre><code>&lt;?php
  dc_header("Речник|Регистрация");
  
  if (!isset($_SESSION['is_logged'])) {
      #header("location: ../views/login.php");
      var_dump($_SESSION);
  }
  </code></pre>
  
  <p>?></p>