Hi,
i want to create cookies in my shopping cart site. I want when i click on add to cart button of
this product. the information of the product save in cookies and destroy when user close his browser.
I want a script. When i create cookies it's work only for one time after reload or refresh the page
the nulled cookies generate automatically and my product information replace with null information.
here are my code.
<?php
error_reporting(E_ALL ^ E_NOTICE);
include("connection.php");
setcookie('pro_id', $_REQUEST['pro_id']);
setcookie('pro_id', $_REQUEST['pro_id'], time()+3600);
setcookie('title', $_REQUEST['title']);
$pro_id = $_COOKIE['pro_id'];
$title = $_COOKIE['title'];
$Special_Product_Sql = "SELECT * FROM product WHERE status = 1 && featured = 1";
$Special_Product_Exe = mysql_query($Special_Product_Sql);
while($Product_Fetch = mysql_fetch_array($Special_Product_Exe)) {
$path = 'product/'. $Product_Fetch['product_img'];
?>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']?>" onsubmit="storeValues(form)" name="form">
<input type="hidden" value="<?php echo $Product_Fetch['pro_id']; ?>" name="pro_id">
<input type="hidden" value="<?php echo $Product_Fetch['title']; ?>" name="title">
<input type="hidden" value="<?php echo $Product_Fetch['description']; ?>" name="field3">
<input type="hidden" value="<?php echo $Product_Fetch['cat_id']; ?>" name="field4">
<input type="submit" title="Add to Cart" value="Add to Cart" class="addtocart_button_module">
</form>
<?php }; ?>
waqar3
0
Newbie Poster
Recommended Answers
Jump to Postsetting cookies on localhost can sometimes be an issue:
setcookie('lang', 'cy', false, "/", false);
I have a routine that sniffs whether the server is production or localhost and applies the last three parameters accordingly. The above is for localhost. An obvious change for a dev environment …
Jump to PostKilling cookies on leaving the site is difficult as they have an expiry time. You could use javascript to kill cookies with the onbreforeunload() function. Your best bet would be to use sessions (
$_SESSION
) to be able to carry data from one page to the next.
Jump to PostI don't see how clearing sessions should affect your db. If an user leaves your site and then comes back to find his basket empty, he'd me pretty cheesed off. The data in the DB can be cleared periodically after a set time with a cron job if needed.
All 9 Replies
diafol
waqar3
0
Newbie Poster
diafol
waqar3
0
Newbie Poster
diafol
waqar3
0
Newbie Poster
diafol
Ponypeet
0
Newbie Poster
waqar3
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.