Jump to content

cant set cookie


NickG21

Recommended Posts

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");

?>

Link to comment
https://forums.phpfreaks.com/topic/70910-cant-set-cookie/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.