Jump to content

Problema com Cookie


luis5566
 Share

Recommended Posts

Boa noite.

Estou a desenvolver um site e deparo-me com o seguinte problema:

Ao usar este código

$cart = $_COOKIE["cart"];
setcookie("cart2", $cart, time()+86500, "/");

O conteúdo da cookie "cart" que é este:

{"name_2":"Camisola","quantity_2":1,"price_2":"20.34","img_2":"http://i.imgur.com/ruU04I6.jpg"}

quando passa para a cookie "cart2" fica assim:

%7B%22name_2%22%3A%22Camisola+de+L%EF%BF%BD%22%2C%22quantity_2%22%3A1%2C%22price_2%22%3A%2220.34%22%2C%22img_2%22%3A%22http%3A%2F%2Fi.imgur.com%2FruU04I6.jpg%22%7D

alguém sabe como resolver este problema?

obg

Edited by luis5566
Link to comment
Share on other sites

isso é normal já que tens isso em json, mas não há problema porque ao leres novamente o valor receberás como gravaste.

O problema é que depois tenho uma função em javascript que dá erro se a cookie estiver assim...

function delItem(id) {
var rd = readCookie("cart2");
var nrd = JSON.parse(rd);
delete nrd['name_'+id];
delete nrd['quantity_'+id];
delete nrd['price_'+id];
delete nrd['img_'+id];
createCookie(JSON.stringify(nrd));
location.reload();
}

com a 1º cookie funciona bem...

Edited by luis5566
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.