title: Prevent new session when opening picture file with PHP
body: <p>Opening a picture file with php is done in a new session, How can I prevent this behaviour?</p>
  
  <p>I have put a javascript in all of my web pages to get screen resolution. Here is the javascript code:</p>
  
  <pre><code> &lt;script language="JavaScript"&gt;
   document.getElementById("mypictureid").src="http://www.mywebsite.com/getresolutionpic.php?w="+screen.width+"&amp;h="+screen.height;
  &lt;/script&gt;
  </code></pre>
  
  <p>and the html of the pages includes:</p>
  
  <pre><code>&lt;img id="mypictureid" src="http://mywebsite.com/otherimage.gif"
  </code></pre>
  
  <p>and the following php code will be executed with each page loading to store user data in $_SESSION.</p>
  
  <pre><code>$some_name = session_name("generalvisit");
  session_start();
  $_SESSION['entertime']=new DateTime();
  </code></pre>
  
  <p>and to track the user a userid is created by a mysql database and stores in $_SESSION['userid']</p>
  
  <pre><code>if(!is_numeric($_SESSION['userid']) $_SESSION['userid']=getNewUserID();
  </code></pre>
  
  <p>now, when the  <code>getresolutionpic.php</code> is triggered by javascript,  store screen resolution of that user stores in the <code>$_SESSION</code> variable of the same user. In <code>getresolutionpic.php</code> we have:</p>
  
  <pre><code>$some_name = session_name("generalvisit");
  session_start();
  if(!is_numeric($_SESSION['userid'])
  {
      $_SESSION['userid']=getNewUserID();
      $_SESSION['entertime']=new DateTime();
  }
  $_SESSION['width']=$_GET['w'];
  $_SESSION['height']=$_GET['h'];
  </code></pre>
  
  <p>The problem is that when getresolutionpic.php is called, <code>$_SESSION['userid']</code> is empty and a new userid will be created while the user is not actually new.</p>
  
  <p>Do you have any idea where it goes wrong?</p>