i have a problem in displaying the values of a cookie dynamically
code goes as...
<?php
$x=array();
include("connect.php");//database connection file
$temp=$_GET;
setcookie(count($x)+1,$temp);
echo $_COOKIE'];
?>

// how do i display the value of cookie every time... it is over written....
i have tried it with using array..
in short i want to display multiple values of single cookie..
value must no overwrite... coz i don't know how many times the user clicks the likn...

This example is taken from PHP.net > setcookie

<?php
// set the cookies
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");

// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
    foreach ($_COOKIE['cookie'] as $name => $value) {
        $name = htmlspecialchars($name);
        $value = htmlspecialchars($value);
        echo "$name : $value <br />\n";
    }
}
?>

but this sets three cookies...
in my site... the creation of cookies depends upon the click on <a> of user....
co how could i know how many times he clicks....

and previous values also should be displayed..
plz. help...

The code you posted originally will create multiple cookies. What are you trying to do? Store a history of what content user's have looked at?

If so, why not store either a serialised array, or a comma separated list?

$data = serialize(array(1, 2, 3, 4);
setcookie('history', $data, ...);

$data = implode(',', array(1, 2, 3, 4));
setcookie('history', $data, ...);

i have a web page that shows list of products with images(from database)

so when the user clicks on any of the image a new page with price and description of that product is open(i did this by transferring the id of clicked image to next page)

and again when the user click on to finally shop that product.. i had passed again that id to next page.. and print it with the use of array of cookie

but when the user performs the same process again for other product...

the previous cookie is overwritten...

Hi..Everyone,

I also applied the same code for cookies in order to save the value. And consecutively value has been saved in cookies as well as fetching in the same function. But If I am trying to fetch the same value in other function then value did not fetch.

I request you guys to help me How to fetch the same value while using the other function.

As you know once the value has been saved in any of function then we can fetch the same value by the means of other function.

1.png

2.png

We can't copy and paste screenshots in order to test your code. Please paste your code