0

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

2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by vinod tik
0

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";
    }
}
?>
0

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

0

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, ...);

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.