I have designed a system to get some user data(screen resolution and etc) by javascript. In HTML files, by javascript, screen resolutions will be send to server via get parameters of a url(an image). the problem is that when the image is requested from server, a new session instance will be created, while I expect that the session for getting the image would be the same as the session of the parent page. please, if you have any idea how could I resolve this problem. thank alot.
the codes I am using are as follows:
I have put a javascript in all of my web pages to get screen resolution. Here is the javascript code:
<script language="JavaScript">
document.getElementById("mypictureid").src="http://www.mywebsite.com/getresolutionpic.php?w="+screen.width+"&h="+screen.height;
</script>
and the html of the pages includes:
<img id="mypictureid" src="http://mywebsite.com/otherimage.gif"
and the following php code will be executed with each page loading to store user data in $_SESSION.
$some_name = session_name("generalvisit");
session_start();
$_SESSION['entertime']=new DateTime();
and to track the user a userid is created by a mysql database and stores in $_SESSION['userid']
if(!is_numeric($_SESSION['userid'])) $_SESSION['userid']=getNewUserID();
now, when the getresolutionpic.php
is triggered by javascript, store screen resolution of that user stores in the $_SESSION
variable of the same user. In getresolutionpic.php
we have:
$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'];
The problem is that when getresolutionpic.php is called, $_SESSION['userid']
is empty and a new userid will be created while the user is not actually new.
Do you have any idea where it goes wrong?