Page 1 of 1

Setting cookie path/domain

Posted: Sat Mar 14, 2009 7:11 am
by ben.artiss
Hi, I've just wrapped my head around paypal's API, so I decided to make a simple shopping cart just to test it out - but I'm having a little trouble because of not setting the right path/domain for the cookies.

As it stands I have '/index.php' which has a short list of items that have an 'Add to cart' link which sends the item ID to '/lib/basket_add.php?item=numericID'. I know it would be fine if I just moved basket_add.php to the root of the site, but I don't want to! :wink: So I've tried the following but it's not working out for me:

Code: Select all

setcookie("basket[0]", $cookie_input, time()+(3600*24*31), 'http://localhost/pptest/');
setcookie("basket[0]", $cookie_input, time()+(3600*24*31), '/', 'http://localhost/pptest/');
I looked at the manual but it says you can specify two paths. Surely if the first argument says where to set the cookie in the domain specified by the second argument... the second example above should work!?

Any tips (or hidden gems) would really be appreciated! Thanks, Ben

Sorry! Sorted it! :)

This site recommends

Code: Select all

setcookie("username", "George", false, "/", false);