NickG21 Posted September 27, 2007 Share Posted September 27, 2007 hey everyone, i am just making a very basic shopping cart/basket on my site and im tracking which user in the DB by putting in their session id as the unique CartID for each user. i have this located in an include file with my database information, and the cookie is not being set, i cannot view it through echo and checking it in IE's temp files and Mozilla's cookie viewer shows it is not being set. i dont understand what i am doing wrong any help will be great, this is my include. <?php $dbusername="blah blah"; $dbpassword="blah"; $database="balahaha"; $host ="localhost"; function GetCartId() { // This function will generate an encrypted string and // will set it as a cookie using set_cookie. This will // also be used as the cookieId field in the cart table if(!isset($_COOKIE['cartId'])) { session_start(); $sess = session_id(); setcookie('cartId', $sess); return $sess; } else { // There is no cookie set. We will set the cookie // and return the value of the users session ID return $_COOKIE['cartId']; } } mysql_connect($host,$dbusername,$dbpassword); @mysql_select_db($database) or die( "Unable to select database"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70910-cant-set-cookie/ Share on other sites More sharing options...
roopurt18 Posted September 27, 2007 Share Posted September 27, 2007 Try adding an expire time to the setcookie() call. Quote Link to comment https://forums.phpfreaks.com/topic/70910-cant-set-cookie/#findComment-356465 Share on other sites More sharing options...
NickG21 Posted September 27, 2007 Author Share Posted September 27, 2007 i have, i originally was setting it as setcookie('cartId', $sess, time() + (3600 * 24)); so i could keep it for one day, but it wasn't working so i tried just setting it without an expiration Quote Link to comment https://forums.phpfreaks.com/topic/70910-cant-set-cookie/#findComment-356493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.