title: Create a session before an ajax call
body: <p>I have this website where I can interact with the web both as a logged or anonymus user. When I click a link I call an ajax function:</p>
  
  <p>you click here:</p>
  
  <pre><code>&lt;a id="alcrearuta" class="'.$row-&gt;urlamigable.'" href="#"&gt;añadir a ruta&lt;/a&gt;
  </code></pre>
  
  <p>This is my ajax function:</p>
  
  <pre><code>var valor=$("#alcrearuta").attr('class');
  $("#alcrearuta").click(function(){
      $.ajax({
          type: "GET",
          url: "../ajax/ruta.php",
          data: "urlamigable=" + valor,
          dataType: 'html',
          success: function(data) {
              $("#listaruta").html(data);
          }
      });        
  });
  </code></pre>
  
  <p>The thing is I have two possibilities: either a logged user clicks the link and the ruta.php does its stuff on the database considering the userid that's set in the session or I have an anonymous user that wants to do something similar.</p>
  
  <p>In my ruta.php I have:</p>
  
  <pre><code>if(!empty($_SESSION['Username'])){
      //Insert stuff on DB
  }else{
      //I wish I could create the session here but I can't since it's an ajax call
  }
  </code></pre>
  
  <p>What I need is at some point between the click in the link and the end of the ajax function I can set my $SESSION['Username'] variable to get a new value (since the user it's not logged in, it's currently empty and thus my inserts on the database not working)</p>