Depending on whether I run my script from domain.com/script.php or http://www.domain.com/script.php , I get two different cookies for each address. The problem is, I may have the ability to create two different cookies, but I only have one way to read the cookies, with the php code:
$cookievalue = $_COOKIE['visitor_']
This particular code only seems to look for domain without the www at the beginning, and so most visitors will not have this cookie unless they come to my site with "domain.com/.. "
I have tried this in IE and firefox and I get the same result. If I visit the page like this domain.com , then I get a user@domain.com cookie only, but when I visit http://www.domain.com I get only a user@www.domain.com cookie.
But $cookievalue = $_COOKIE['visitor_'] will only read the cookie without the www.
Is there some php setting I need to change to fix this? Basically I need to either set a cookie for both domains at once, or be able to read either cookies specifically. Any ideas?
Having major difficulty with cookies
Moderator: General Moderators
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
its when you set the cookie, you need the . infront of the domain like this
Code: Select all
setcookie('visitor_', $value, time()+3600, '/', '.domain.com');-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
I tried doing this.
on the main page I have this
every time he clicks on a link he is sent to a script that has this code in it
$referer_url always seems to come up empty
on the main page I have this
Code: Select all
if (!empty($_COOKIE['visitor_'])) {
setcookie ("visitor_", "", time()-60000);
setcookie ('visitor_', $url, time() + (60*60*24),'/','.domain.net');
}
// Otherwise he is unique (new or hasn't visited in 24 hours)
else{
setcookie ('visitor_', $url, time() + (60*60*24),'/','.domain.net');
$unique_=1;
}Code: Select all
$referer_url = $_COOKIE['visitor_'];