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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.