note 40365 deleted from function.setcookie by tularis
| From: | tularis@php.net | Date: | Sun, 02 Jan 2005 14:17:25 +0000 |
| Subject: | note 40365 deleted from function.setcookie by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82579@lists.php.net to get a copy of this message | ||
Note Submitter: trouby at hotmail dot com
----
I had the following problem, I was creating a stat script. Each user on my site will get an ID based
on there browser configuration and their IP address. When the user pops on my website, the first
time they will get:
<?php
// index.php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Refresh: 1");
print "<script language='javascript'
src='tstat.js'></script>";
}
else
print "welcome";
?>
// tstat.js
document.write('<img src="http://www.example.com/make_id.php?var1=bla"
/>');
<?php
// make_id.php
session_start();
$_SESSION['user_id'] = trb_makeID(); // my own function which generates an ID (not
important)
?>
Now let's say my site is www.example.com and when I enter the site for the first time, the
javascript will be printed and that javascript will connect to my make_id.php, which will assign the
variable 'user_id', now when the brower will refresh, the script will print
'welcome'.
This all worked for me, BUT there were user which had trouble entering my site, after spending one
whole day researching what could be the problem, I noticed that they entered my site
'example.com' and the javascript will print an image to 'www.example.com' so
those visitors had launched two sessions at the same time and that resulted in a constant refresh..
My solution was to set my own session cookies with a correct domain. example.com and www.example.com
are to different values for your browser!