title: PHP session not registering the first time
body: <p>I am having an issue with the session variables.</p>
  
  <p>I am having a simple signup php page that uses ajax calls to verify username and email address if they already exist. It also has an ajax image uploader that gives a preview of the selected image.</p>
  
  <p>Now this is how I am setting the session variable :-</p>
  
  <pre><code>session_start();
  session_unset();
  $_SESSION = array();
  
  if (ini_get("session.use_cookies")) {
      $params = session_get_cookie_params();
      setcookie(session_name(), '', time() - 42000,
          $params["path"], $params["domain"],
          $params["secure"], $params["httponly"]
      );
  }
  
  session_destroy();
  session_start();
  
  $_SESSION['avurl'] = $filename;
  </code></pre>
  
  <p>$filename is valid as it is echoed in the above code just after this snippet.</p>
  
  <p>In the page where I need to use this session variable I have this :-</p>
  
  <pre><code>session_start();
  
  $av_url = $_SESSION['avurl'];
  </code></pre>
  
  <p>Now the weird thing is that whenever this runs the first time the session variable doesn't have any value. But the second time it works.</p>
  
  <p>How I came to check this is that I created a test.php which just echos $_SESSION['avurl'] and the first time it never shows anything but the second time it does.</p>
  
  <p>What I figured out from this is that once it echoes this session variable it starts working to store the value.</p>
  
  <p>And all that code that I am using to set that variable is edited from just :-</p>
  
  <pre><code>session_start();
  
  $_SESSION['avurl'] = $filename;
  </code></pre>
  
  <p>to that as this also didn't work and I thought that this could be a problem with already existing sessions.</p>
  
  <p>Thankyou
  Hope this is enough information for solving my problem !!</p>