Strange cookie and session problem

hay.

I’m having a very strange issue regarding cookies and sessions

Basically i have a shopping cart script which creates a cookie for each visitor which is then used
to store their shopping cart stuff via a text file on the server.

when adding an item to cart the data is saved and displayed fine but the issue is when they click the view cart link

here is the add to cart link:
http://rockinglocks.com/new/dreadlock_products/residue_free_dreadlock_shampoo.html

when you have clicked the add to cart button, follow up by goin to view cart
http://www.rockinglocks.com/new/viewcart.php

now all i see is 0! nothing in the cart.

now heres where it gets strange lol… this next page is exaclty the same as the other page
except for the page name:
http://rockinglocks.com/new/test.php

this one does as it viewcart.php should do displaying the correct cart details

if i rename the test.php file to viewcart.php on the server to does as the other viewcart.php page did…nothing

can anyone help me out with this… does ot not like the file name lol??

i have also tried this with sessions and i get the same problem

cheers

ok…

i have no idea why but i have located the problem but not sure how to fix it yet

the issue is the “www” part of the domain

check this out lol

after adding an item to the cart - try these to urls

http://rockinglocks.com/new/viewcart.php

http://www.rockinglocks.com/new/viewcart.php

only works with NO “www” in url

how crazy, any ideas on how to fix this or is it a server issue?

cheers

fixed the problem :o

ok for anyone else who may have this totally crazy issue

set your cookies with the domain name

example:
[php]

setcookie(‘mycookie’,“value”, time()+3600, “/”, “yourdomain.com”);

[/php]

cant believe i have wasted hours for this >:(

ive never had to set a cookie that way before lol

oh well

does anyone know why i would have to set the domain in the cookie for this to work?

i get and understand what setting the domain does but is there a php or achache setting that is forcing me to set the domain in the cookie in order to get the cookie to work on both www.mysite.com and mysite.com

i have done some testing today and the hosting company say its nothing to do with them lol

check this out

look at this page and follow the instructions

http://rockinglocks.com/new/test.php

this will set a cookie when refreshed…

now add the www

http://www.rockinglocks.com/new/test.php

messgae will say cookie NOT set hit refresh

this will then create 2 cookies 1 for rockinglocks.com and one for www.rockinglocks.comhttp://www.rockinglocks.com (check your browser cookie)

ok now go here

http://rockinglocks.com/new/test1.php

again do the refresh thing and cookie is set

now try here

http://www.rockinglocks.com/new/test1.php

boom! no need to refresh!

the difference?

in test.php we have “setcookie(“test-php”,“something”,time()+3600);”

in test1.php we have “setcookie(“test1-php”,“something”,time()+3600, “/”, “rockinglocks.com”);”

ok so what server setting would be wanting me to add the domain?

any ideas

cheers

Sponsor our Newsletter | Privacy Policy | Terms of Service